From e1e6a7a98b53ae437d0f60afa8cd81d2d63c037b Mon Sep 17 00:00:00 2001 From: giles Date: Wed, 11 Feb 2026 16:00:32 +0000 Subject: [PATCH] Import all app model packages at startup for SQLAlchemy mapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cross-domain relationships like Product.order_items → OrderItem use string references that SQLAlchemy resolves by class name lookup. All model packages must be imported so every class is registered before mapper configuration runs. Co-Authored-By: Claude Opus 4.6 --- infrastructure/factory.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/infrastructure/factory.py b/infrastructure/factory.py index c79845f..a1814eb 100644 --- a/infrastructure/factory.py +++ b/infrastructure/factory.py @@ -8,7 +8,14 @@ from typing import Callable, Awaitable, Sequence from quart import Quart, request, g, send_from_directory from shared.config import init_config, config, pretty -from shared.models import KV # ensure models imported +from shared.models import KV # ensure shared models imported +# Register all app model classes with SQLAlchemy so cross-domain +# relationship() string references resolve correctly. +for _mod in ("blog.models", "market.models", "cart.models", "events.models"): + try: + __import__(_mod) + except ImportError: + pass from shared.log_config import configure_logging from shared.events import EventProcessor