Skip to content

Commit e65673e

Browse files
ramonechenCopilot
andauthored
Prevent duplicate router registration
Co-authored-by: Copilot <[email protected]>
1 parent d77e1b6 commit e65673e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def scan_and_include_routers(app: FastAPI) -> None:
1515
module = importlib.import_module(f"{package_module_name}.{module_name}")
1616
for attr_name in dir(module):
1717
attr = getattr(module, attr_name)
18-
if isinstance(attr, APIRouter):
18+
if isinstance(attr, APIRouter) and getattr(attr, "__module__", None) == module.__name__:
1919
app.include_router(attr)
2020

2121

0 commit comments

Comments
 (0)