Fix SQLAlchemy 2.x compatibility: wrap raw SQL in text()
SQLAlchemy 2.x requires raw SQL strings to be explicitly wrapped in text(). Fixed 16 instances across 5 route files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from typing import Any, Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Header
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import text
|
||||
|
||||
from database import SessionLocal
|
||||
|
||||
@@ -75,13 +76,13 @@ async def get_compliance_scope(
|
||||
db = SessionLocal()
|
||||
try:
|
||||
row = db.execute(
|
||||
"""SELECT tenant_id,
|
||||
text("""SELECT tenant_id,
|
||||
state->'compliance_scope' AS scope,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM sdk_states
|
||||
WHERE tenant_id = :tid
|
||||
AND state ? 'compliance_scope'""",
|
||||
AND state ? 'compliance_scope'"""),
|
||||
{"tid": tid},
|
||||
).fetchone()
|
||||
|
||||
@@ -106,22 +107,22 @@ async def upsert_compliance_scope(
|
||||
db = SessionLocal()
|
||||
try:
|
||||
db.execute(
|
||||
"""INSERT INTO sdk_states (tenant_id, state)
|
||||
text("""INSERT INTO sdk_states (tenant_id, state)
|
||||
VALUES (:tid, jsonb_build_object('compliance_scope', :scope::jsonb))
|
||||
ON CONFLICT (tenant_id) DO UPDATE
|
||||
SET state = sdk_states.state || jsonb_build_object('compliance_scope', :scope::jsonb),
|
||||
updated_at = NOW()""",
|
||||
updated_at = NOW()"""),
|
||||
{"tid": tid, "scope": scope_json},
|
||||
)
|
||||
db.commit()
|
||||
|
||||
row = db.execute(
|
||||
"""SELECT tenant_id,
|
||||
text("""SELECT tenant_id,
|
||||
state->'compliance_scope' AS scope,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM sdk_states
|
||||
WHERE tenant_id = :tid""",
|
||||
WHERE tenant_id = :tid"""),
|
||||
{"tid": tid},
|
||||
).fetchone()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user