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
lekss361 commented 2026-05-15 05:09:38 +00:00 (Migrated from github.com)

Bug

Production POST /api/v1/admin/site-finder/weight-profiles → 500 SyntaxError.

```
syntax error at or near ":"
LINE 5: ($1, $2, :weights::jsonb, $3, $4)
^
parameters: {user_id, profile_name, is_default, description}
↑ 'weights' missing
```

Root cause

SQLAlchemy text() parser двусмысленно с `:weights::jsonb`:

  • `:weights` — named param (должен → `%(weights)s`)
  • `::jsonb` — PG cast operator

Parser НЕ binds `:weights` когда followed by `::`. Psycopg видит literal `:weights` → syntax error.

Fix

`:weights::jsonb` → `CAST(:weights AS jsonb)` (2 мест):

  • `_INSERT` для create_profile
  • `_UPDATE` dynamic set для update_profile

CAST() syntax unambiguous, parser correctly binds.

Affected

  • POST `/admin/site-finder/weight-profiles` (create) — 500 → 201
  • PUT `/admin/site-finder/weight-profiles/{id}` (update with weights) — 500 → 200

Impact

Feature #114 Custom POI weights не работает в production ДО этого fix.

Refs: user report 2026-05-15

## Bug Production POST /api/v1/admin/site-finder/weight-profiles → **500 SyntaxError**. \`\`\` syntax error at or near \":\" LINE 5: (\$1, \$2, :weights::jsonb, \$3, \$4) ^ parameters: {user_id, profile_name, is_default, description} ↑ 'weights' missing \`\`\` ## Root cause SQLAlchemy text() parser двусмысленно с \`:weights::jsonb\`: - \`:weights\` — named param (должен → \`%(weights)s\`) - \`::jsonb\` — PG cast operator Parser **НЕ binds** \`:weights\` когда followed by \`::\`. Psycopg видит literal \`:weights\` → syntax error. ## Fix \`:weights::jsonb\` → \`CAST(:weights AS jsonb)\` (2 мест): - \`_INSERT\` для create_profile - \`_UPDATE\` dynamic set для update_profile CAST() syntax unambiguous, parser correctly binds. ## Affected - POST \`/admin/site-finder/weight-profiles\` (create) — 500 → 201 - PUT \`/admin/site-finder/weight-profiles/{id}\` (update with weights) — 500 → 200 ## Impact Feature #114 Custom POI weights не работает в production ДО этого fix. Refs: user report 2026-05-15
lekss361 commented 2026-05-15 05:12:09 +00:00 (Migrated from github.com)

Final review (SHA 6164826, CI )

  • Backend SUCCESS, frontend SUCCESS
  • SQLAlchemy :param::castCAST(:param AS cast) стандартный workaround
  • Surgical (+2/-2), unblocks feature #114 в prod

approve merge

## Final review (SHA `6164826`, CI ✅) - Backend SUCCESS, frontend SUCCESS - SQLAlchemy `:param::cast` → `CAST(:param AS cast)` стандартный workaround - Surgical (+2/-2), unblocks feature #114 в prod approve merge
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#152
No description provided.