Skip to content

Stormheg/django-36739-manage-py-check-unexpected-database-access

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django bug report

This is a minimal Django project to demonstrate an issue where manage.py check has started to unexpectedly interact with the database if you use django.db.models.JSONField in the project. This did not happen in earlier revisions.

The situation I encountered this issue with is recreated in this project. It happens when calling manage.py check from a pytest test which is not decorated with pytest.mark.django_db. This used to work before in Django 6.0b1 but now raises RuntimeError: Database access not allowed, use the "django_db" mark to enable it.

Expected behavior

  • manage.py check should not attempt to access the database, unless explicitly asked to do so.

Environment

Steps to reproduce

To reproduce the issue, follow these steps:

  1. Clone this repository.
  2. Create and activate a virtual environment (i.e. python -m venv venv and source venv/bin/activate on macOS/Linux or venv\Scripts\activate on Windows).
  3. Install the required development dependencies: pip install -r requirements.txt.
  4. Install Django from the suspect revision: pip install git+https://github.com/django/django.git@3aba1fced8254435b947467739721ec6b4fb865c.
  5. Run the tests using pytest: pytest.

This should give the following error output:

F                                                                        [100%]
=================================== FAILURES ===================================
__________________________ test_sample_command_output __________________________

capsys = <_pytest.capture.CaptureFixture object at 0x10a0ff0e0>

    def test_sample_command_output(capsys):
>       call_command("check")

tests/test_sample.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.14/site-packages/django/core/management/__init__.py:195: in call_command
    return command.execute(*args, **defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/core/management/base.py:460: in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/core/management/commands/check.py:81: in handle
    self.check(
venv/lib/python3.14/site-packages/django/core/management/base.py:492: in check
    all_issues = checks.run_checks(
venv/lib/python3.14/site-packages/django/core/checks/registry.py:98: in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/core/checks/model_checks.py:36: in check_all_models
    errors.extend(model.check(**kwargs))
                  ^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/models/base.py:1770: in check
    *cls._check_fields(**kwargs),
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/models/base.py:1933: in _check_fields
    errors.extend(field.check(**kwargs))
                  ^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/models/fields/json.py:52: in check
    errors.extend(self._check_supported(databases))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/models/fields/json.py:68: in _check_supported
    or connection.features.supports_json_field
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/utils/functional.py:47: in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/backends/sqlite3/features.py:157: in supports_json_field
    with self.connection.cursor() as cursor:
         ^^^^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/utils/asyncio.py:26: in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
venv/lib/python3.14/site-packages/django/db/backends/base/base.py:320: in cursor
    return self._cursor()
           ^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <DatabaseWrapper vendor='sqlite' alias='default'>, name = None

    def _cursor(self, name=None):
        self.close_if_health_check_failed()
>       self.ensure_connection()
E       RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.

venv/lib/python3.14/site-packages/django/db/backends/base/base.py:296: RuntimeError
=========================== short test summary info ============================
FAILED tests/test_sample.py::test_sample_command_output - RuntimeError: Datab...
1 failed in 0.10s

Releases

No releases published

Packages

No packages published

Languages