fix(topology): adapt queries for psycopg 3 array syntax

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-09 20:53:48 +08:00
co-authored by Claude
parent adf3c60688
commit b5156d1306
+5 -5
View File
@@ -131,11 +131,11 @@ def fetch_snapshot(snapshot_at):
return result return result
# --- ports --- # --- ports ---
component_ids = tuple(component_map.keys()) component_ids = list(component_map.keys())
cur.execute(""" cur.execute("""
SELECT id, component_id, port_key, display_name, direction, interface_type SELECT id, component_id, port_key, display_name, direction, interface_type
FROM ports FROM ports
WHERE component_id IN %(ids)s WHERE component_id = ANY(%(ids)s)
ORDER BY component_id, port_key ORDER BY component_id, port_key
""", {"ids": component_ids}) """, {"ids": component_ids})
port_map = {} port_map = {}
@@ -158,7 +158,7 @@ def fetch_snapshot(snapshot_at):
cur.execute(""" cur.execute("""
SELECT component_id, state_kind, state_value, details SELECT component_id, state_kind, state_value, details
FROM component_states FROM component_states
WHERE component_id IN %(ids)s WHERE component_id = ANY(%(ids)s)
AND valid_from <= %(at)s::timestamptz AND valid_from <= %(at)s::timestamptz
AND (valid_to IS NULL OR %(at)s::timestamptz < valid_to) AND (valid_to IS NULL OR %(at)s::timestamptz < valid_to)
ORDER BY component_id, state_kind ORDER BY component_id, state_kind
@@ -185,8 +185,8 @@ def fetch_snapshot(snapshot_at):
WHERE tc.base_id = (SELECT id FROM bases WHERE code = 'guanghan') WHERE tc.base_id = (SELECT id FROM bases WHERE code = 'guanghan')
AND tc.valid_from <= %(at)s::timestamptz AND tc.valid_from <= %(at)s::timestamptz
AND (tc.valid_to IS NULL OR %(at)s::timestamptz < tc.valid_to) AND (tc.valid_to IS NULL OR %(at)s::timestamptz < tc.valid_to)
AND pa.component_id IN %(ids)s AND pa.component_id = ANY(%(ids)s)
AND pb.component_id IN %(ids)s AND pb.component_id = ANY(%(ids)s)
ORDER BY tc.connection_type, pa.port_key ORDER BY tc.connection_type, pa.port_key
""", {"ids": component_ids, "at": snapshot_at}) """, {"ids": component_ids, "at": snapshot_at})
for row in cur.fetchall(): for row in cur.fetchall():