From ca219f1ac94b55292ddce6f409c242c1084075db Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sun, 26 May 2024 01:10:18 +0100 Subject: [PATCH] Fix joining Shift+ShiftEntry, unhack volunteer schedule_ical https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html leads me to believe this was just a bug in the definition of current_count. --- apps/volunteer/schedule.py | 3 +-- models/volunteer/shift.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/volunteer/schedule.py b/apps/volunteer/schedule.py index 175d343e3..039b565f8 100644 --- a/apps/volunteer/schedule.py +++ b/apps/volunteer/schedule.py @@ -6,7 +6,7 @@ from flask import current_app as app from collections import defaultdict from flask_login import current_user -from sqlalchemy.orm import joinedload, defer +from sqlalchemy.orm import joinedload from main import db from models import event_year @@ -121,7 +121,6 @@ def schedule_ical(): .select_from(ShiftEntry) .join(Shift.entries.and_(ShiftEntry.user == user)) .options( - defer(Shift.current_count), # the subquery for that column breaks this query joinedload(Shift.venue), joinedload(Shift.role) )).all() diff --git a/models/volunteer/shift.py b/models/volunteer/shift.py index 33f70e292..2325a2430 100644 --- a/models/volunteer/shift.py +++ b/models/volunteer/shift.py @@ -71,7 +71,7 @@ class Shift(BaseModel): proposal = db.relationship("Proposal", backref="shift") current_count = db.column_property( - select([func.count(ShiftEntry.shift_id)]).where(ShiftEntry.shift_id == id).scalar_subquery() # type: ignore[attr-defined] + select([func.count(ShiftEntry.shift_id)]).where(ShiftEntry.shift_id == id).correlate_except(ShiftEntry).scalar_subquery() # type: ignore[attr-defined] ) duration = db.column_property(end - start)