Skip to content

Respect an explicit autodiscover list under Django#697

Merged
wbarnha merged 1 commit into
masterfrom
claude/fix-500-django-autodiscover
Jul 21, 2026
Merged

Respect an explicit autodiscover list under Django#697
wbarnha merged 1 commit into
masterfrom
claude/fix-500-django-autodiscover

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 19, 2026

Copy link
Copy Markdown
Member

Note: Before submitting this pull request, please review our contributing guidelines.

Description

Fixes #500.

App.discover() unconditionally unioned every fixup's autodiscover_modules() into the set of modules to scan:

for fixup in self.fixups:
    modules |= set(fixup.autodiscover_modules())

The Django fixup's autodiscover_modules() 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 frequently failing.

This contradicts the Django fixup's own documented behavior:

If faust.App(autodiscovery=True), the Django fixup will automatically autodiscover agents/tasks/web views … found in installed Django apps.

i.e. the INSTALLED_APPS scan is meant for the blanket autodiscover=True mode, 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 via Fixup.on_worker_init() (which calls django.setup()), so this does not affect Django initialization — only which modules get scanned for @app.agent/task/view decorators.

Tests

  • Updated test_discover (explicit list): asserts the fixup's modules (d, e) are not imported and fixup.autodiscover_modules is not called.
  • Added test_discover__true_includes_fixup_modules: with autodiscover=True, the fixup modules are scanned.
  • Verified the updated test catches the bug: reverting the fix makes d/e get imported for the explicit-list case.
  • flake8 / black --check / isort --check-only clean.

🤖 Generated with Claude Code


Generated by Claude Code

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

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (3073eb9) to head (8192c98).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wbarnha
wbarnha added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit 0e83780 Jul 21, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autodiscover doesn't work properly

1 participant