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

Merged
lekss361 merged 1 commit from fix/weight-profiles-sqlalchemy-cast-syntax into main 2026-05-15 05:12:18 +00:00

1 commit

Author SHA1 Message Date
lekss361
6164826805 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
2026-05-15 08:09:32 +03:00