fix(nspd-geo): rosreestr2coord v5 compat — delay arg, tmp cache, dumps default

Three incremental bugs surfaced while wiring rosreestr2coord v5 into our
worker. All in backend/app/services/scrapers/nspd_lite.py.

1. `Area.__init__()` removed `delay` kwarg in v5 (was throttling). Drop
   it from our call. Rate limit now happens in worker via
   time.sleep(rate_ms/1000) after each fetch.

2. `Area(..., use_cache=True)` default writes media cache to ./tmp/
   relative to CWD. In our docker image CWD=/app (owned by root), worker
   runs as non-root → PermissionError on every target. Fix:
   use_cache=False, media_path="/tmp/rosreestr2coord".

3. `Area.to_geojson_poly(dumps=True)` default returns JSON-serialized
   STRING, not dict (changed in v5). Worker's _persist_target expects
   dict with .get("properties") → AttributeError. Fix: dumps=False.

Vault entries:
- fixes/Bug_Rosreestr2coord_Delay_Arg_v5_Fixed.md
- fixes/Bug_Nspd_Geo_Tmp_Permission_Fixed.md
- fixes/Bug_Nspd_Geo_Str_Object_No_Get_Fixed.md
This commit is contained in:
lekss361 2026-05-11 14:43:44 +03:00
parent 5b741578e6
commit ce5e29f92e

View file

@ -179,7 +179,10 @@ def fetch_via_rosreestr2coord(
media_path="/tmp/rosreestr2coord",
)
try:
return a.to_geojson_poly()
# dumps=False — возвращает dict (GeoJSON Feature), а не JSON-сериализованную
# строку. Default в v5 = True → строка → крах в `_persist_target` который
# ожидает dict с `.get("properties")` etc.
return a.to_geojson_poly(dumps=False)
except Exception as e:
logger.warning("rosreestr2coord failed for %s: %s", cad_num, e)
return None