fix: replace all :: type casts with CAST() in SQLAlchemy text() calls
SQLAlchemy's text() interprets :name::type as two named parameters. Fixes syntax errors in link discovery, signal history, and SNMP profile CRUD that caused 500 errors at runtime. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -163,7 +163,7 @@ async def create_profile(
|
||||
category, profile_data, is_system)
|
||||
VALUES
|
||||
(:tenant_id, :name, :description, :sys_object_id, :vendor,
|
||||
:category, :profile_data::jsonb, FALSE)
|
||||
:category, CAST(:profile_data AS jsonb), FALSE)
|
||||
RETURNING id, tenant_id, name, description, sys_object_id, vendor,
|
||||
category, is_system, created_at, updated_at
|
||||
"""),
|
||||
@@ -234,7 +234,7 @@ async def update_profile(
|
||||
|
||||
for field, value in fields.items():
|
||||
if field == "profile_data" and value is not None:
|
||||
set_clauses.append(f"{field} = :{field}::jsonb")
|
||||
set_clauses.append(f"{field} = CAST(:{field} AS jsonb)")
|
||||
updates[field] = json.dumps(value)
|
||||
else:
|
||||
set_clauses.append(f"{field} = :{field}")
|
||||
|
||||
@@ -106,8 +106,8 @@ async def on_wireless_registration_for_links(msg) -> None:
|
||||
(gen_random_uuid(), :ap_device_id, :cpe_device_id, :tenant_id,
|
||||
:interface, :client_mac, :signal_strength, :tx_ccq, :tx_rate,
|
||||
:rx_rate,
|
||||
CASE WHEN :signal_strength::int IS NULL THEN 'active'
|
||||
WHEN :signal_strength::int < :degraded_threshold THEN 'degraded'
|
||||
CASE WHEN CAST(:signal_strength AS int) IS NULL THEN 'active'
|
||||
WHEN CAST(:signal_strength AS int) < :degraded_threshold THEN 'degraded'
|
||||
ELSE 'active' END,
|
||||
0, NOW(), NOW(), NOW())
|
||||
ON CONFLICT (ap_device_id, cpe_device_id) DO UPDATE SET
|
||||
@@ -152,7 +152,7 @@ async def on_wireless_registration_for_links(msg) -> None:
|
||||
WHERE ap_device_id = :ap_device_id
|
||||
AND tenant_id = :tenant_id
|
||||
AND cpe_device_id NOT IN (
|
||||
SELECT unnest(:seen_cpe_ids::uuid[])
|
||||
SELECT unnest(CAST(:seen_cpe_ids AS uuid[]))
|
||||
)
|
||||
AND state NOT IN ('down', 'stale')
|
||||
"""),
|
||||
|
||||
@@ -51,7 +51,7 @@ async def get_signal_history(
|
||||
WHERE wr.mac_address = :mac_address
|
||||
AND wr.device_id = :device_id
|
||||
AND wr.tenant_id = :tenant_id
|
||||
AND wr.time > now() - :lookback::interval
|
||||
AND wr.time > now() - CAST(:lookback AS interval)
|
||||
AND wr.signal_strength IS NOT NULL
|
||||
GROUP BY bucket
|
||||
ORDER BY bucket
|
||||
|
||||
Reference in New Issue
Block a user