From 733d7816c5fa173b6d32c1f1b9a26c1f2c6f6e96 Mon Sep 17 00:00:00 2001 From: Chandra Y Date: Mon, 9 Dec 2024 16:30:09 -0600 Subject: [PATCH] Quick Fix: APCD, List registrations for submitter is broken (#398) * Fix syntax error in sql * move left join before where --- apcd_cms/src/apps/utils/apcd_database.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apcd_cms/src/apps/utils/apcd_database.py b/apcd_cms/src/apps/utils/apcd_database.py index 4a8865fc..495a0854 100644 --- a/apcd_cms/src/apps/utils/apcd_database.py +++ b/apcd_cms/src/apps/utils/apcd_database.py @@ -177,11 +177,12 @@ def get_registrations(reg_id=None, submitter_code=None): registrations.state, registrations.zip, registrations.registration_year - FROM registrations - {f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''} - {f"LEFT JOIN registration_submitters on registrations.registration_id = registration_submitters.registration_id LEFT JOIN submitters ON registration_submitters.submitter_id = submitters.submitter_id WHERE submitter_code = ANY(%s) ORDER BY registrations.registration_id" if submitter_code is not None else ''} - ORDER BY registrations.registration_id desc""" - + FROM registrations + {f"LEFT JOIN registration_submitters ON registrations.registration_id = registration_submitters.registration_id LEFT JOIN submitters ON registration_submitters.submitter_id = submitters.submitter_id" if submitter_code is not None else ''} + WHERE 1=1 + {f" AND registrations.registration_id = {str(reg_id)}" if reg_id is not None else ''} + {f" AND submitters.submitter_code = ANY(%s)" if submitter_code is not None else ''} + ORDER BY registrations.registration_id""" cur = conn.cursor() if submitter_code: cur.execute(query, (submitter_code,))