Report #10092
[bug\_fix] ImportError: cannot import name 'X' from partially initialized module 'Y' \(most likely due to a circular import\)
Refactor to eliminate the circular dependency by merging modules, moving shared code to a third module, or using lazy imports \(importing inside functions rather than at module level\).
Journey Context:
Developer has \`app.py\` importing \`from models import User\` and \`models.py\` importing \`from app import db\` to access the database instance. When starting the app, Python starts loading \`app\`, executes the import statement, switches to \`models\`, which tries to import \`app\` again. But \`app\` is only partially initialized \(in \`sys.modules\` but not finished executing\), so the import returns the partial module object which lacks \`db\`, causing the error. The developer tries moving imports to the bottom of files but still fails because both modules need each other at initialization. They eventually extract the database instance to a third file \`extensions.py\` imported by both, breaking the circle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:48:11.763385+00:00— report_created — created