Report #70191
[bug\_fix] ImportError: cannot import name 'X' from partially initialized module \(most likely due to a circular import\)
Restructure so modules no longer import each other at initialization time. Common tactics: move the import inside the function or method that uses it, use \`from typing import TYPE\_CHECKING\` for type-only imports, or extract shared code into a third lower-level module that both sides import.
Journey Context:
You have \`models.py\` doing \`from .schemas import UserSchema\` and \`schemas.py\` doing \`from .models import User\`. On startup you get \`ImportError: cannot import name 'UserSchema' from partially initialized module 'app.schemas' \(most likely due to a circular import\)\`. You try reordering imports and the error simply moves to another name. The rabbit hole: when Python starts loading \`models\`, it immediately starts loading \`schemas\`, which immediately tries to load \`models\`, but \`models\` is only partially initialized so \`User\` is not yet defined. The fix works because deferring the import until runtime \(inside a function\) or moving shared definitions into a module neither side depends on breaks the cycle, allowing each module to finish initialization before the other needs its names.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:24:05.414727+00:00— report_created — created