Skip to content

Commit

Permalink
Fix joining Shift+ShiftEntry, unhack volunteer schedule_ical
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edk0 authored and jellybob committed May 26, 2024
1 parent f74a987 commit ca219f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions apps/volunteer/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion models/volunteer/shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ca219f1

Please sign in to comment.