From 0401a71fce1756faa042bd7d012f3be9120d0693 Mon Sep 17 00:00:00 2001 From: Kyle Pope Date: Mon, 16 Mar 2026 20:39:40 +0800 Subject: [PATCH] Fix CompoundSelect chaining: use standalone union_all() SQLAlchemy 2.0's select().union_all() returns a CompoundSelect which cannot chain another .union_all(). Use the standalone union_all() function to combine all three queries. Co-Authored-By: Claude Opus 4.6 --- backend/app/services/calendar_sharing.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/app/services/calendar_sharing.py b/backend/app/services/calendar_sharing.py index fd446fb..fea6df9 100644 --- a/backend/app/services/calendar_sharing.py +++ b/backend/app/services/calendar_sharing.py @@ -7,7 +7,7 @@ import logging from datetime import datetime, timedelta from fastapi import HTTPException -from sqlalchemy import delete, literal_column, select, text, update +from sqlalchemy import delete, literal_column, select, text, union_all, update from sqlalchemy.ext.asyncio import AsyncSession from app.models.calendar import Calendar @@ -45,21 +45,19 @@ async def get_accessible_event_scope( from app.models.event_invitation import EventInvitation result = await db.execute( - select(literal_column("'c'").label("kind"), Calendar.id.label("val")) - .where(Calendar.user_id == user_id) - .union_all( + union_all( + select(literal_column("'c'").label("kind"), Calendar.id.label("val")) + .where(Calendar.user_id == user_id), select(literal_column("'c'"), CalendarMember.calendar_id) .where( CalendarMember.user_id == user_id, CalendarMember.status == "accepted", - ) - ) - .union_all( + ), select(literal_column("'i'"), EventInvitation.event_id) .where( EventInvitation.user_id == user_id, EventInvitation.status != "declined", - ) + ), ) ) cal_ids: list[int] = []