fix(shell): silence the shell model auto-import banner (docker + manual runs)#15234
Open
Maffooch wants to merge 2 commits into
Open
fix(shell): silence the shell model auto-import banner (docker + manual runs)#15234Maffooch wants to merge 2 commits into
Maffooch wants to merge 2 commits into
Conversation
…t scripts
reach_database.sh and entrypoint-first-boot.sh pipe short scripts into
`manage.py shell` (a DB connectivity check and superuser creation). Since
Django 5.1 the shell command auto-imports every model on startup and prints
a banner like:
36 objects could not be automatically imported:
dojo.auditlog.services.ObjectsProductTags
...
237 objects imported automatically (use -v 2 for details).
The "could not be imported" entries are dynamically-generated Tagulous tag
models and auditlog proxies that aren't importable by their dotted path, so
the list looks alarming on every container start even though nothing is
wrong. Both scripts import exactly what they need, so pass --no-imports
(Django >= 5.2) to skip the auto-import and drop the noise. The piped code
still runs and exit codes are unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Manual `manage.py shell` runs still showed the auto-import failure banner (the docker --no-imports change only covered the DB-reach / first-boot scripts). Override the shell command's get_auto_imports() to keep only paths that actually import, so dynamically-generated Tagulous tag models and auditlog proxy models no longer appear as "could not be automatically imported". Real models still auto-import; the filter is generic (tries the import, keeps what succeeds) so it also covers Pro's proxy models. Adds unittests/test_shell_command.py asserting every returned path imports, real models are kept, and the dropped paths are all genuinely non-importable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mtesauro
previously approved these changes
Jul 14, 2026
When did these tests break? They showed green when I approved this...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Since Django 5.1,
manage.py shellauto-imports every model on startup and prints a banner on every invocation:The "could not be imported" entries are dynamically-generated Tagulous tag models (
Tagulous_*_tags) and auditlog proxy models — they exist on the app registry but aren't importable by their"<module>.<name>"path, so Django's auto-import can't resolve them. Nothing is actually wrong, but the list reads as an error.This showed up in two places, both covered here:
1. Container startup scripts
docker/reach_database.sh(DB connectivity check) anddocker/entrypoint-first-boot.sh(superuser creation) pipe short scripts intomanage.py shell. They import exactly what they need, so they pass--no-imports(Django ≥ 5.2; the project pins 5.2.14) to skip auto-import entirely. The piped code still runs and exit codes are unchanged.2. Manual
manage.py shellrunsDevelopers running
shellby hand won't pass--no-imports, so adojo/management/commands/shell.pyoverride filtersget_auto_imports()down to paths that actually import. Real models still auto-import; the banner is clean. The filter is generic (it tries the import and keeps what succeeds), so it also covers Pro's proxy models without Pro needing its own override.Testing
On Django 5.2.14:
reach_database.sh's connection test with--no-imports: banner gone,echo $?=0.manage.py shell: prints only237 objects imported automatically— no "could not be imported" list;Findingand other real models still auto-import.unittests/test_shell_command.py(new): asserts every path returned byget_auto_imports()imports, that real models are kept, and that every dropped path is genuinely non-importable. Green.ruff --config ruff.tomlclean on the new files.