fix(gisogd66): CAST(:geojson AS text) — AmbiguousParameter ронял каждый upsert
All checks were successful
CI / changes (pull_request) Successful in 8s
CI Trade-In / changes (pull_request) Successful in 8s
CI / frontend-tests (pull_request) Has been skipped
CI Trade-In / backend-tests (pull_request) Has been skipped
CI Trade-In / frontend-checks (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Successful in 2m11s
CI / backend-tests (pull_request) Successful in 15m5s

Второй прод-прогон: 11235 карточек скачано, 0 вставлено — все upsert'ы
падали psycopg.errors.AmbiguousParameter ($10): ни одно вхождение
:geojson (CASE WHEN + перегруженная ST_GeomFromGeoJSON text/json/jsonb)
не давало Postgres тип параметра. Тесты не ловили — БД в них замокана.

Refs #2367
This commit is contained in:
bot-backend 2026-07-04 11:38:31 +05:00
parent ae3278f92f
commit cf3a23112d

View file

@ -277,8 +277,12 @@ def _upsert_permit(db: Session, rec: dict[str, Any]) -> str:
:doc_group, :doc_num, :doc_name, :date_doc, :date_reg,
:approved_org, :source_schema, :source_key,
CAST(:cad_nums AS text[]),
CASE WHEN :geojson IS NULL THEN NULL
ELSE ST_Multi(ST_SetSRID(ST_GeomFromGeoJSON(:geojson), 4326)) END,
-- CAST обязателен: без него ни одно вхождение :geojson не даёт Postgres
-- тип параметра (ST_GeomFromGeoJSON перегружена text/json/jsonb)
-- psycopg.errors.AmbiguousParameter на КАЖДОЙ строке (прод-прогон #2367).
CASE WHEN CAST(:geojson AS text) IS NULL THEN NULL
ELSE ST_Multi(ST_SetSRID(
ST_GeomFromGeoJSON(CAST(:geojson AS text)), 4326)) END,
NOW(), NOW()
)
ON CONFLICT (doc_group, doc_num) DO UPDATE