From 86c7e83886bdc2f3f063cf709605a4570e3f656d Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Sat, 28 Mar 2026 05:54:49 +0100 Subject: [PATCH] fix: handle lazy loading error for company.category in chat routes --- blueprints/chat/routes.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/blueprints/chat/routes.py b/blueprints/chat/routes.py index 36990da..6c60966 100644 --- a/blueprints/chat/routes.py +++ b/blueprints/chat/routes.py @@ -272,12 +272,17 @@ def chat_send_message(conversation_id): 'user_email': current_user.email, 'company_name': current_user.company.name if current_user.company else None, 'company_id': current_user.company.id if current_user.company else None, - 'company_category': current_user.company.category.name if current_user.company and current_user.company.category else None, + 'company_category': None, 'company_role': current_user.company_role or 'MEMBER', 'is_norda_member': current_user.is_norda_member, 'chamber_role': current_user.chamber_role, 'member_since': current_user.created_at.strftime('%Y-%m-%d') if current_user.created_at else None, } + try: + if current_user.company and current_user.company.category: + user_context['company_category'] = current_user.company.category.name + except Exception: + pass # Map model choice to actual model name and thinking level model_map = { @@ -364,12 +369,17 @@ def chat_send_message_stream(conversation_id): 'user_email': current_user.email, 'company_name': current_user.company.name if current_user.company else None, 'company_id': current_user.company.id if current_user.company else None, - 'company_category': current_user.company.category.name if current_user.company and current_user.company.category else None, + 'company_category': None, 'company_role': current_user.company_role or 'MEMBER', 'is_norda_member': current_user.is_norda_member, 'chamber_role': current_user.chamber_role, 'member_since': current_user.created_at.strftime('%Y-%m-%d') if current_user.created_at else None, } + try: + if current_user.company and current_user.company.category: + user_context['company_category'] = current_user.company.category.name + except Exception: + pass model_map = { 'flash': '3-flash',