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 <noreply@anthropic.com>
This commit is contained in:
parent
8f087ccebf
commit
0401a71fce
@ -7,7 +7,7 @@ import logging
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from fastapi import HTTPException
|
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 sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.models.calendar import Calendar
|
from app.models.calendar import Calendar
|
||||||
@ -45,21 +45,19 @@ async def get_accessible_event_scope(
|
|||||||
from app.models.event_invitation import EventInvitation
|
from app.models.event_invitation import EventInvitation
|
||||||
|
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
select(literal_column("'c'").label("kind"), Calendar.id.label("val"))
|
union_all(
|
||||||
.where(Calendar.user_id == user_id)
|
select(literal_column("'c'").label("kind"), Calendar.id.label("val"))
|
||||||
.union_all(
|
.where(Calendar.user_id == user_id),
|
||||||
select(literal_column("'c'"), CalendarMember.calendar_id)
|
select(literal_column("'c'"), CalendarMember.calendar_id)
|
||||||
.where(
|
.where(
|
||||||
CalendarMember.user_id == user_id,
|
CalendarMember.user_id == user_id,
|
||||||
CalendarMember.status == "accepted",
|
CalendarMember.status == "accepted",
|
||||||
)
|
),
|
||||||
)
|
|
||||||
.union_all(
|
|
||||||
select(literal_column("'i'"), EventInvitation.event_id)
|
select(literal_column("'i'"), EventInvitation.event_id)
|
||||||
.where(
|
.where(
|
||||||
EventInvitation.user_id == user_id,
|
EventInvitation.user_id == user_id,
|
||||||
EventInvitation.status != "declined",
|
EventInvitation.status != "declined",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cal_ids: list[int] = []
|
cal_ids: list[int] = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user