fix(flowpilot): fix session detail 500 — build AISessionDetail manually
Root cause: AISessionDetail.model_validate(session) tried to validate the ORM relationship 'steps' which has field 'id', but AISessionStepResponse expects 'step_id'. This caused a Pydantic ValidationError on every session detail load. Fix: Construct AISessionDetail manually from ORM fields, passing the already-built step_responses list directly instead of relying on model_validate to serialize the ORM steps relationship. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -645,16 +645,33 @@ async def get_session(
|
|||||||
confidence_score=step.confidence_at_step,
|
confidence_score=step.confidence_at_step,
|
||||||
))
|
))
|
||||||
|
|
||||||
try:
|
# Build detail manually — AISessionDetail.model_validate(session) fails because
|
||||||
detail = AISessionDetail.model_validate(session)
|
# the ORM relationship 'steps' has 'id' not 'step_id', causing validation errors.
|
||||||
detail.steps = step_responses
|
# Instead, extract non-step fields from ORM and set step_responses separately.
|
||||||
return detail
|
detail = AISessionDetail(
|
||||||
except Exception as e:
|
id=session.id,
|
||||||
logger.exception("Failed to serialize session %s: %s", session_id, e)
|
status=session.status,
|
||||||
raise HTTPException(
|
intake_type=session.intake_type,
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
intake_content=session.intake_content or {},
|
||||||
detail=f"Session serialization error: {type(e).__name__}: {str(e)[:200]}",
|
problem_summary=session.problem_summary,
|
||||||
)
|
problem_domain=session.problem_domain,
|
||||||
|
confidence_tier=session.confidence_tier,
|
||||||
|
step_count=session.step_count,
|
||||||
|
session_rating=session.session_rating,
|
||||||
|
psa_ticket_id=session.psa_ticket_id,
|
||||||
|
psa_connection_id=session.psa_connection_id,
|
||||||
|
escalation_reason=session.escalation_reason,
|
||||||
|
matched_flow_id=session.matched_flow_id,
|
||||||
|
match_score=getattr(session, 'match_score', None),
|
||||||
|
resolution_summary=session.resolution_summary,
|
||||||
|
resolution_action=getattr(session, 'resolution_action', None),
|
||||||
|
session_feedback=session.session_feedback,
|
||||||
|
ticket_data=session.ticket_data,
|
||||||
|
created_at=session.created_at,
|
||||||
|
resolved_at=session.resolved_at,
|
||||||
|
steps=step_responses,
|
||||||
|
)
|
||||||
|
return detail
|
||||||
|
|
||||||
|
|
||||||
# ── Documentation ──
|
# ── Documentation ──
|
||||||
|
|||||||
Reference in New Issue
Block a user