05/16 Fix bugs 2

This commit is contained in:
Nguyen Ngo
2026-05-16 14:02:53 -04:00
parent 0675acb8ec
commit edd81f4c59
7 changed files with 104 additions and 6 deletions
+6 -1
View File
@@ -110,9 +110,14 @@ def index():
recent_inspections = recent_q.limit(5).all()
# ── Pending follow-up inspections ────────────────────────────────────
# follow_ups is a lazy='dynamic' relationship — comparing it to None does
# NOT produce a "has no rows" predicate for dynamic relationships. The
# correct idiom is ~.any(), which generates EXISTS (SELECT 1 FROM inspections
# WHERE parent_inspection_id = inspections.id). This matches the identical
# filter used in routes/inspections.py:follow_up_filter.
followup_q = Inspection.query.filter_by(
follow_up_required=True, status='completed'
).filter(Inspection.follow_ups == None) # noqa: E711 — SQLAlchemy usage
).filter(~Inspection.follow_ups.any())
if is_inspector:
followup_q = followup_q.filter(Inspection.inspector_id == current_user.id)
elif is_customer: