fix(site-finder): SQLAlchemy syntax error :weights::jsonb → CAST(:weights AS jsonb)

Production POST /weight-profiles → 500 SyntaxError.

## Root cause

SQLAlchemy text() parser трактует ':weights' followed by '::jsonb' двусмысленно:
- ':weights' — named param binding (должен стать %(weights)s)
- '::jsonb' — PG cast operator

Parser НЕ распознаёт :weights как параметр когда сразу следует :: cast.
Result: psycopg видит literal ':weights' в SQL → syntax error.

```
LINE 5: ($1, $2, :weights::jsonb, $3, $4)
                   ^
parameters: {user_id, profile_name, is_default, description}
            ↑ note: 'weights' missing — SQLAlchemy skipped it
```

## Fix

Replace ambiguous :weights::jsonb с CAST(:weights AS jsonb):
- _INSERT (line 102)
- _UPDATE dynamic 'weights = :weights::jsonb' (line 273)

CAST() syntax не имеет ambiguity, SQLAlchemy корректно bind'ит :weights.

## Affected endpoints

- POST /api/v1/admin/site-finder/weight-profiles (create)
- PUT /api/v1/admin/site-finder/weight-profiles/{id} (update with weights)

Refs: user report 2026-05-15
This commit is contained in:
lekss361 2026-05-15 08:09:32 +03:00
parent 7c43bc5496
commit 6164826805

View file

@ -99,7 +99,7 @@ _INSERT = """
INSERT INTO user_weight_profiles
(user_id, profile_name, weights, is_default, description)
VALUES
(:user_id, :profile_name, :weights::jsonb, :is_default, :description)
(:user_id, :profile_name, CAST(:weights AS jsonb), :is_default, :description)
RETURNING id, created_at, updated_at
"""
@ -270,7 +270,7 @@ def update_profile(
params["profile_name"] = payload.profile_name
if payload.weights is not None:
sets.append("weights = :weights::jsonb")
sets.append("weights = CAST(:weights AS jsonb)")
params["weights"] = json.dumps(payload.weights, ensure_ascii=False)
if payload.description is not None: