Skip to content

Repro issue 713#776

Closed
prescod wants to merge 2 commits intopytest-dev:masterfrom
prescod:repro-issue-713
Closed

Repro issue 713#776
prescod wants to merge 2 commits intopytest-dev:masterfrom
prescod:repro-issue-713

Conversation

@prescod
Copy link

@prescod prescod commented Oct 23, 2019

I built on Michel Samia's work to reformat into the format suggested by @blueyed.

#713

@blueyed
Copy link
Contributor

blueyed commented Oct 23, 2019

That's a problem with pytest's saferepr not handling its own "Failed" exception, which is a BaseException (pytest-dev/pytest#6047).

Fixing that then shows this failure with your test:

============== test session starts ===============
platform linux -- Python 3.7.4, pytest-5.2.2.dev101+gf0c2b070c, py-1.7.0, pluggy-0.12.0 -- /home/daniel/Vcs/pytest-django/.venv/bin/python
cachedir: .pytest_cache
Django settings: tpkg.the_settings (from command line option)
rootdir: /tmp/pytest-of-daniel/pytest-8/test_migration_should_not_cause_internal_error0, inifile: tox.ini
plugins: forked-0.2, xdist-1.29.0, cov-2.6.1, django-3.6.1.dev1+ng2a93cd3.d20191018
collected 1 item

tpkg/test_the_test.py::test_inner_migrations Creating test database for alias 'default' ('/tmp/test_zawk6cdj_inner')...
Destroying old test database for alias 'default' ('/tmp/test_zawk6cdj_inner')...
Operations to perform:
  Apply all migrations: app, auth, contenttypes
Running migrations:
  Applying app.0001_initial... OK
  Applying app.0002_seed_data...ERROR

===================== ERRORS =====================
____ ERROR at setup of test_inner_migrations _____

request = <SubRequest '_django_db_marker' for <Function test_inner_migrations>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request):
        """Implement the django_db marker, internal to pytest-django.

        This will dynamically request the ``db``, ``transactional_db`` or
        ``django_db_reset_sequences`` fixtures as required by the django_db marker.
        """
        marker = request.node.get_closest_marker("django_db")
        if marker:
            transaction, reset_sequences = validate_django_db(marker)
            if reset_sequences:
                request.getfixturevalue("django_db_reset_sequences")
            elif transaction:
                request.getfixturevalue("transactional_db")
            else:
>               request.getfixturevalue("db")

/home/daniel/Vcs/pytest-django/pytest_django/plugin.py:511:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/daniel/Vcs/pytest-django/pytest_django/fixtures.py:108: in django_db_setup
    **setup_databases_args
/home/daniel/Vcs/django/django/test/utils.py:173: in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
/home/daniel/Vcs/django/django/db/backends/base/creation.py:72: in create_test_db
    run_syncdb=True,
/home/daniel/Vcs/django/django/core/management/__init__.py:168: in call_command
    return command.execute(*args, **defaults)
/home/daniel/Vcs/django/django/core/management/base.py:369: in execute
    output = self.handle(*args, **options)
/home/daniel/Vcs/django/django/core/management/base.py:83: in wrapped
    res = handle_func(*args, **kwargs)
/home/daniel/Vcs/django/django/core/management/commands/migrate.py:233: in handle
    fake_initial=fake_initial,
/home/daniel/Vcs/django/django/db/migrations/executor.py:117: in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
/home/daniel/Vcs/django/django/db/migrations/executor.py:147: in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
/home/daniel/Vcs/django/django/db/migrations/executor.py:245: in apply_migration
    state = migration.apply(state, schema_editor)
/home/daniel/Vcs/django/django/db/migrations/migration.py:124: in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
/home/daniel/Vcs/django/django/db/migrations/operations/special.py:190: in database_forwards
    self.code(from_state.apps, schema_editor)
tpkg/app/migrations/0002_seed_data.py:9: in cb_seed_items
    Item.objects.get(name='This one is not there')
/home/daniel/Vcs/django/django/db/models/manager.py:82: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[Failed("Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.") raised in repr()] QuerySet object at 0x7f99e78e7890>
args = ()
kwargs = {'name': 'This one is not there'}
clone = <QuerySet []>, limit = 21, num = 0

    def get(self, *args, **kwargs):
        """
        Perform the query and return a single object matching the given
        keyword arguments.
        """
        clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
        if self.query.can_filter() and not self.query.distinct_fields:
            clone = clone.order_by()
        limit = None
        if not clone.query.select_for_update or connections[clone.db].features.supports_select_for_update_with_limit:
            limit = MAX_GET_RESULTS
            clone.query.set_limits(high=limit)
        num = len(clone)
        if num == 1:
            return clone._result_cache[0]
        if not num:
            raise self.model.DoesNotExist(
                "%s matching query does not exist." %
>               self.model._meta.object_name
            )
E           __fake__.Item.DoesNotExist: Item matching query does not exist.

/home/daniel/Vcs/django/django/db/models/query.py:414: DoesNotExist
============ short test summary info =============
ERROR tpkg/test_the_test.py::test_inner_migrations
=

blueyed added a commit to blueyed/pytest that referenced this pull request Oct 23, 2019
@blueyed
Copy link
Contributor

blueyed commented Oct 23, 2019

That's the crucial part, where pytest fails:

self = <[Failed("Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.") raised in repr()] QuerySet object at 0x7f99e78e7890>

(this is fix the pending fix for pytest)

@blueyed
Copy link
Contributor

blueyed commented Oct 23, 2019

So is that the issue then after all?
Or do you expect the test to behave different from raising "E fake.Item.DoesNotExist: Item matching query does not exist."?

blueyed added a commit to blueyed/pytest that referenced this pull request Oct 23, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 23, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 23, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
@blueyed
Copy link
Contributor

blueyed commented Oct 23, 2019

Followup in #777 (could not push here - see the checkbox on the right).

@blueyed blueyed closed this Oct 23, 2019
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Oct 31, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Nov 6, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
blueyed added a commit to blueyed/pytest that referenced this pull request Nov 6, 2019
This causes INTERNALERRORs with pytest-django, which uses
`pytest.fail` (derived from `BaseException`) to prevent DB access, when
pytest then tries to e.g. display the `repr()` for a Django `QuerySet`
etc.

Ref: pytest-dev/pytest-django#776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants