pytest-dev / pytest-dev/pytest-django

Fixture django_db_setup stopped working when upgrading from 4.6 to 4.7

Open
#1,115 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

I've been using a custom django_db_setup fixture which has worked for years. After upgrading from 4.6 to 4.7 this suddenly doesn't work anymore, resulting in the following error:

RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.

This might be a bug. Anybody any idea how to fix this from 4.7?
The fixture is something like this:

@pytest.yield_fixture(scope="session", autouse=True)
def django_db_setup(django_db_blocker):
    with django_db_blocker.unblock():
        # Code that requires DB access and populates data required for all tests.
        Model.objects.create()

        # At this point the DB setup for the tests is complete
        yield

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the custom session-scoped django_db_setup fixture shown in the report and compare its behavior on versions 4.6 and 4.7, focusing on django_db_blocker.unblock(). Confirm the expected database-access behavior during setup, then capture a regression test or migration guidance once the cause is established.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
databases, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.