Opened 11 years ago
Closed 11 years ago
#21770 closed Bug (fixed)
Management commands autocomplete broken
Reported by: | Akis Kesoglou | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Release blocker | Keywords: | app-loading |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Tabbing for command autocompletion in manage.py raises the following error:
$ ./manage.py sql<Tab> Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/<virtualenv>/src/django/django/core/management/__init__.py", line 426, in execute_from_command_line utility.execute() File "/<virtualenv>/src/django/django/core/management/__init__.py", line 379, in execute self.autocomplete() File "/<virtualenv>/src/django/django/core/management/__init__.py", line 326, in autocomplete subcommands = list(get_commands()) + ['help'] File "/<virtualenv>/bin/../lib/python3.3/functools.py", line 251, in wrapper result = user_function(*args, **kwds) File "/<virtualenv>/src/django/django/core/management/__init__.py", line 118, in get_commands app_configs = apps.get_app_configs() File "/<virtualenv>/src/django/django/apps/registry.py", line 121, in get_app_configs self.check_ready() File "/<virtualenv>/src/django/django/apps/registry.py", line 115, in check_ready raise RuntimeError("App registry isn't ready yet.") RuntimeError: App registry isn't ready yet.
Bringing the issue up in #django-dev, mjtamlyn suggested moving the try/catch with django.setup() block to the beginning of ManagementUtility.execute() method, which fixed the issue. However, the change broke the test suite, specifically many tests from test_admin_scripts.
I'm not at all familiar with that (huge) part of the test suite, so i'm not sure how to go about it, even though i'm willing to help.
Python 3.3, Django@9918c11114ac3
Change History (6)
comment:1 by , 11 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Keywords: | app-loading added; AppConfig admin_script manage django-admin removed |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
An alternative would be to import only apps, not models.
I'm reluctant to add this to the app registry for the sole purpose of autocompletion.
comment:5 by , 11 years ago
I tried the patch and it works here too. FWIW, I personally didn't see any noticeable difference in autocompletion delay, though the project I tried it on has only about 15-20 models including Django's.
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
The following patch fixes the issue:
It also makes autocompletion much slower. In order to discover management commands in applications referenced by an AppConfig in INSTALLED_APPS, one must populate the app registry, and that's slow.
I don't see how we can avoid it.