Skip to content

fix(shell): silence the shell model auto-import banner (docker + manual runs)#15234

Open
Maffooch wants to merge 2 commits into
bugfixfrom
fix/reach-database-shell-no-imports
Open

fix(shell): silence the shell model auto-import banner (docker + manual runs)#15234
Maffooch wants to merge 2 commits into
bugfixfrom
fix/reach-database-shell-no-imports

Conversation

@Maffooch

@Maffooch Maffooch commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What

Since Django 5.1, manage.py shell auto-imports every model on startup and prints a banner on every invocation:

36 objects could not be automatically imported:

  dojo.auditlog.services.ObjectsProductTags
  dojo.location.models.Tagulous_Location_tags
  pro.auditlog.RoleProxy
  ...

237 objects imported automatically (use -v 2 for details).

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) and docker/entrypoint-first-boot.sh (superuser creation) pipe short scripts into manage.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 shell runs

Developers running shell by hand won't pass --no-imports, so a dojo/management/commands/shell.py override filters get_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.
  • Manual manage.py shell: prints only 237 objects imported automatically — no "could not be imported" list; Finding and other real models still auto-import.
  • unittests/test_shell_command.py (new): asserts every path returned by get_auto_imports() imports, that real models are kept, and that every dropped path is genuinely non-importable. Green.
  • ruff --config ruff.toml clean on the new files.

…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>
@Maffooch Maffooch requested a review from blakeaowens as a code owner July 13, 2026 19:18
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>
@Maffooch Maffooch changed the title fix(docker): silence shell auto-import banner in DB-reach / first-boot scripts fix(shell): silence the shell model auto-import banner (docker + manual runs) Jul 13, 2026
mtesauro
mtesauro previously approved these changes Jul 14, 2026

@mtesauro mtesauro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's going on with those tests

@mtesauro mtesauro dismissed their stale review July 14, 2026 01:13

When did these tests break? They showed green when I approved this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants