From 2facfd7a8d6c8fa6593443fb8177c23d8d84bafb Mon Sep 17 00:00:00 2001 From: Aditya Vaish Date: Thu, 16 Oct 2025 10:21:28 +0530 Subject: [PATCH] CRITICAL FIX: Add missing SQLAlchemy relationships to SearchSpace class - Added search_source_connectors relationship (back_populates from SearchSourceConnector) - Added llm_configs relationship (back_populates from LLMConfig) - Added user_preferences relationship (back_populates from UserSearchSpacePreference) - Prevents SQLAlchemy InvalidRequestError on application startup - Fixes broken ORM mappings that would crash the entire application This resolves the critical issue where SQLAlchemy could not find the required relationships, preventing the application from starting. --- surfsense_backend/app/db.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/surfsense_backend/app/db.py b/surfsense_backend/app/db.py index 0ff01646c..648a1434a 100644 --- a/surfsense_backend/app/db.py +++ b/surfsense_backend/app/db.py @@ -260,6 +260,24 @@ class SearchSpace(BaseModel, TimestampMixin): order_by="ConnectorSchedule.id", cascade="all, delete-orphan", ) + search_source_connectors = relationship( + "SearchSourceConnector", + back_populates="search_space", + order_by="SearchSourceConnector.id", + cascade="all, delete-orphan", + ) + llm_configs = relationship( + "LLMConfig", + back_populates="search_space", + order_by="LLMConfig.id", + cascade="all, delete-orphan", + ) + user_preferences = relationship( + "UserSearchSpacePreference", + back_populates="search_space", + order_by="UserSearchSpacePreference.id", + cascade="all, delete-orphan", + ) class SearchSourceConnector(BaseModel, TimestampMixin):