aditya-rAj19 commited on
Commit
83651d7
Β·
1 Parent(s): 0550cee

Fix: list_locations resilient when message column missing (was showing 0)

Browse files

If the locations table hasn't had the message column added yet, selecting it
returned an error and the whole list came back empty. Now it retries without
message, so locations always show; custom messages activate once the ALTER runs.

Files changed (1) hide show
  1. core/supabase_store.py +16 -4
core/supabase_store.py CHANGED
@@ -59,19 +59,31 @@ def _image_path(gender: str, name: str) -> str:
59
  # ── locations table ───────────────────────────────────────────────────────────
60
 
61
  def list_locations(gender: str) -> list:
62
- """[{folder, label, has_image}] for a gender, ordered by sort_order."""
63
- try:
 
 
 
 
64
  r = requests.get(
65
  f"{SUPABASE_URL}/rest/v1/locations",
66
  headers=_rest_headers(),
67
  params={"gender": f"eq.{gender}", "order": "sort_order.asc,name.asc",
68
- "select": "name,image_path,sort_order,message"},
69
  timeout=_TIMEOUT,
70
  )
71
  r.raise_for_status()
 
 
 
 
 
 
 
 
72
  return [{"folder": row["name"], "label": row["name"],
73
  "has_image": bool(row.get("image_path")),
74
- "message": row.get("message") or ""} for row in r.json()]
75
  except Exception as e:
76
  print(f"[supabase] list_locations failed: {e}")
77
  return []
 
59
  # ── locations table ───────────────────────────────────────────────────────────
60
 
61
  def list_locations(gender: str) -> list:
62
+ """
63
+ [{folder, label, has_image, message}] for a gender, ordered by sort_order.
64
+ Resilient to the `message` column not existing yet (older schema): falls
65
+ back to a select without it instead of returning nothing.
66
+ """
67
+ def _query(select):
68
  r = requests.get(
69
  f"{SUPABASE_URL}/rest/v1/locations",
70
  headers=_rest_headers(),
71
  params={"gender": f"eq.{gender}", "order": "sort_order.asc,name.asc",
72
+ "select": select},
73
  timeout=_TIMEOUT,
74
  )
75
  r.raise_for_status()
76
+ return r.json()
77
+
78
+ try:
79
+ try:
80
+ rows = _query("name,image_path,sort_order,message")
81
+ except Exception:
82
+ # `message` column missing (schema not migrated) β€” retry without it.
83
+ rows = _query("name,image_path,sort_order")
84
  return [{"folder": row["name"], "label": row["name"],
85
  "has_image": bool(row.get("image_path")),
86
+ "message": row.get("message") or ""} for row in rows]
87
  except Exception as e:
88
  print(f"[supabase] list_locations failed: {e}")
89
  return []