Opened 7 days ago

Closed 3 days ago

Last modified 3 days ago

#36224 closed Bug (fixed)

django-admin shell raises AppRegistryNotReady

Reported by: Raffaella Owned by: Sarah Boyce
Component: Core (Management commands) Version: 5.2
Severity: Release blocker Keywords: shell
Cc: Raffaella, Natalia Bidart, Salvo Polizzi Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried to open the shell with django-admin shell after installing Django 5.2b1, but I got this error. The problem could be related to the new feature of automatic models import in the shell.

Traceback (most recent call last):
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/bin/django-admin", line 8, in <module>
    sys.exit(execute_from_command_line())
             ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/commands/shell.py", line 250, in handle
    return getattr(self, shell)(options)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/commands/shell.py", line 70, in python
    imported_objects = self.get_namespace(**options)
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/commands/shell.py", line 153, in get_namespace
    path_imports = self.get_auto_imports()
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/core/management/commands/shell.py", line 144, in get_auto_imports
    for model in reversed(apps.get_models())
                          ~~~~~~~~~~~~~~~^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/apps/registry.py", line 181, in get_models
    self.check_models_ready()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/raffi/PycharmProjects/debug-tutorial/.venv/lib/python3.13/site-packages/django/apps/registry.py", line 143, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Change History (7)

comment:1 by Sarah Boyce, 7 days ago

Severity: NormalRelease blocker
Summary: Shell raise an AppRegistryNotReadydjango-admin shell raises AppRegistryNotReady
Triage Stage: UnreviewedAccepted

Thank you for testing!

comment:2 by Sarah Boyce, 7 days ago

Cc: Natalia Bidart Salvo Polizzi added
Has patch: set
Owner: set to Sarah Boyce

comment:3 by Natalia Bidart, 6 days ago

Patch needs improvement: set

comment:4 by Sarah Boyce, 5 days ago

Patch needs improvement: unset

comment:5 by Natalia Bidart, 3 days ago

Triage Stage: AcceptedReady for checkin

comment:6 by Sarah Boyce <42296566+sarahboyce@…>, 3 days ago

Resolution: fixed
Status: assignedclosed

In de1117ea:

Fixed #36224 -- Fixed shell imports when settings not configured.

Thank you Raffaella for the report. Thank you Tim Schilling and Natalia Bidart
for the reviews.

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 3 days ago

In 4c7b737b:

[5.2.x] Fixed #36224 -- Fixed shell imports when settings not configured.

Thank you Raffaella for the report. Thank you Tim Schilling and Natalia Bidart
for the reviews.

Backport of de1117ea8eabe0ee0aa048e5a4e249eab7c4245e from main.

Note: See TracTickets for help on using tickets.
Back to Top