From 1817a6fe6150ea36da839429e9ef3bb9c002cada Mon Sep 17 00:00:00 2001 From: Ashwin Date: Tue, 4 Aug 2026 22:48:55 +0530 Subject: [PATCH] fix: resolve ambiguous column reference in case list filters --- backend/cases/views.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/cases/views.py b/backend/cases/views.py index 7bbc84dc..54f2fd43 100644 --- a/backend/cases/views.py +++ b/backend/cases/views.py @@ -129,15 +129,22 @@ def apply_case_list_filters(queryset, params): # business hours, but the badges on both clients compute from # created_at + hours, so this filter mirrors what the user actually # sees on the row. Postgres-specific (INTERVAL). + # + # Every column is table-qualified. Unqualified, these resolve fine + # against a bare Case queryset and raise + # `ProgrammingError: column reference "first_response_at" is ambiguous` + # the moment the queryset joins a table sharing any of these names, + # which is what a filter combination such as `?sla_breached=true` plus + # a status list produced: a 500 for any authenticated caller. queryset = queryset.extra( where=[ - "(first_response_at IS NULL " - "AND sla_first_response_hours IS NOT NULL " - "AND created_at + sla_first_response_hours " + '("case"."first_response_at" IS NULL ' + 'AND "case"."sla_first_response_hours" IS NOT NULL ' + 'AND "case"."created_at" + "case"."sla_first_response_hours" ' "* INTERVAL '1 hour' < NOW()) " - "OR (resolved_at IS NULL " - "AND sla_resolution_hours IS NOT NULL " - "AND created_at + sla_resolution_hours " + 'OR ("case"."resolved_at" IS NULL ' + 'AND "case"."sla_resolution_hours" IS NOT NULL ' + 'AND "case"."created_at" + "case"."sla_resolution_hours" ' "* INTERVAL '1 hour' < NOW())" ] )