Respect an explicit autodiscover list under Django#697
Merged
Conversation
App.discover() unconditionally unioned every fixup's autodiscover_modules()
into the set of modules to scan. The Django fixup returns all of
INSTALLED_APPS, so an app that set an explicit list --
e.g. autodiscover=['myproj.agents'] -- still had every installed Django app
scanned, importing unrelated migrations/admin modules and often failing.
This contradicts the Django fixup's own documented behavior ("If
autodiscover=True, the Django fixup will automatically autodiscover ... in
installed Django apps"). Only pull in fixup-provided modules for the
blanket autodiscover=True mode; when the user passes an explicit list (or a
callable), honor it as-is. Django is still set up independently via
Fixup.on_worker_init(), so this doesn't affect Django initialization.
Fixes #500.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #697 +/- ##
=======================================
Coverage 94.14% 94.15%
=======================================
Files 104 104
Lines 11136 11137 +1
Branches 1201 1202 +1
=======================================
+ Hits 10484 10486 +2
+ Misses 551 550 -1
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Note: Before submitting this pull request, please review our contributing guidelines.
Description
Fixes #500.
App.discover()unconditionally unioned every fixup'sautodiscover_modules()into the set of modules to scan:The Django fixup's
autodiscover_modules()returns all ofINSTALLED_APPS. So an app that set an explicit list — e.g.autodiscover=['myproj.agents']— still had every installed Django app scanned, importing unrelatedmigrations/adminmodules and frequently failing.This contradicts the Django fixup's own documented behavior:
i.e. the INSTALLED_APPS scan is meant for the blanket
autodiscover=Truemode, not for an explicit list.Fix
Only pull in fixup-provided modules when
conf.autodiscover is True. When the user passes an explicit list (or a callable), honor it as-is. Django itself is still set up independently viaFixup.on_worker_init()(which callsdjango.setup()), so this does not affect Django initialization — only which modules get scanned for@app.agent/task/view decorators.Tests
test_discover(explicit list): asserts the fixup's modules (d,e) are not imported andfixup.autodiscover_modulesis not called.test_discover__true_includes_fixup_modules: withautodiscover=True, the fixup modules are scanned.d/eget imported for the explicit-list case.flake8/black --check/isort --check-onlyclean.🤖 Generated with Claude Code
Generated by Claude Code