From db0d841ef007a30df6640831cc2124542a050dbb Mon Sep 17 00:00:00 2001 From: Jack Levy Date: Sun, 15 Mar 2026 11:01:24 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20API=20health=20check=20=E2=80=94=20corre?= =?UTF-8?q?ct=20TIGERweb=20CD=20field=20detection=20in=20admin=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same bug as members.py: health check used old CD\d+FP$ regex (no match for CD119) and skipped GEOID. Now mirrors members.py logic: GEOID primary, STATE+CD\d+ fallback, Congressional layer filter. Authored by: Jack Levy --- backend/app/api/admin.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/app/api/admin.py b/backend/app/api/admin.py index 9acc227..12c1276 100644 --- a/backend/app/api/admin.py +++ b/backend/app/api/admin.py @@ -473,9 +473,18 @@ def _test_rep_lookup() -> dict: r2.raise_for_status() results = r2.json().get("results", []) for item in results: + if "Congressional" not in (item.get("layerName") or ""): + continue attrs = item.get("attributes", {}) - cd_field = next((k for k in attrs if _re.match(r"CD\d+FP$", k)), None) - if cd_field: + # Primary: GEOID = state FIPS (2) + district (2) + geoid = str(attrs.get("GEOID") or "").strip() + if len(geoid) == 4 and geoid.isdigit(): + district = str(int(geoid[2:])) if geoid[2:].strip("0") else "At-large" + return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"} + # Fallback: STATE + CD{session} (e.g. STATE="06", CD119="30") + state_val = attrs.get("STATE") + cd_field = next((k for k in attrs if _re.match(r"CD\d+$", k)), None) + if state_val and cd_field: district = str(int(str(attrs[cd_field]))) if str(attrs[cd_field]).strip("0") else "At-large" return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"} layers = [r.get("layerName") for r in results]