From 83247a221129a6f4616483aa1172db18e6d5d6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Fri, 14 Feb 2025 16:40:37 +0100 Subject: [PATCH] fix: unhandled exception when member hash is not correct --- govtool/backend/sql/list-proposals.sql | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index cedc4e86d..2c0de7f10 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -85,10 +85,13 @@ EnrichedCurrentMembers AS ( ) AS enriched_members FROM ProcessedCurrentMembers pcm - LEFT JOIN - json_array_elements(pcm.current_members) AS member ON true - LEFT JOIN - CommitteeData cm ON cm.hash = encode(decode(member->>'hash', 'hex'), 'hex') + LEFT JOIN json_array_elements(pcm.current_members) AS member ON true + LEFT JOIN CommitteeData cm + ON (CASE + WHEN (member->>'hash') ~ '^[0-9a-fA-F]+$' + THEN encode(decode(member->>'hash', 'hex'), 'hex') + ELSE NULL + END) = cm.hash GROUP BY pcm.id ), @@ -199,7 +202,13 @@ SELECT 'tag', pd.tag, 'members', em.enriched_members, 'membersToBeRemoved', mtr.members_to_be_removed, - 'threshold', pd.threshold::float + 'threshold', + CASE + WHEN (pd.threshold->>'numerator') IS NOT NULL + AND (pd.threshold->>'denominator') IS NOT NULL + THEN (pd.threshold->>'numerator')::float / (pd.threshold->>'denominator')::float + ELSE NULL + END ) FROM ParsedDescription pd