fix: Unwrap CEIDG /firma/{id} response structure {"firma": [{...}]}
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

The detail endpoint wraps firm data in a lista under "firma" key.
Without unwrapping, the list of dicts was assigned to legal_name (String),
causing psycopg2 ProgrammingError: can't adapt type 'dict'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-02-18 15:06:19 +01:00
parent a67d069f81
commit e60dd010c3

View File

@ -30,12 +30,23 @@ CEIDG_TIMEOUT = 15 # seconds
def _fetch_firma_detail(firma_id: str, headers: dict) -> Optional[Dict[str, Any]]: def _fetch_firma_detail(firma_id: str, headers: dict) -> Optional[Dict[str, Any]]:
"""Phase 2: Fetch full company details from /firma/{id} endpoint.""" """Phase 2: Fetch full company details from /firma/{id} endpoint.
The API returns {"firma": [{...}]} unwrap to get the actual firm dict.
"""
url = f"{CEIDG_API_BASE}/firma/{firma_id}" url = f"{CEIDG_API_BASE}/firma/{firma_id}"
try: try:
response = requests.get(url, headers=headers, timeout=CEIDG_TIMEOUT) response = requests.get(url, headers=headers, timeout=CEIDG_TIMEOUT)
if response.status_code == 200: if response.status_code == 200:
return response.json() data = response.json()
# Unwrap: /firma/{id} returns {"firma": [{...company data...}]}
if isinstance(data, dict) and 'firma' in data:
firmy = data['firma']
if isinstance(firmy, list) and firmy:
return firmy[0]
if isinstance(firmy, dict):
return firmy
return data
logger.warning(f"CEIDG detail endpoint returned {response.status_code} for id={firma_id}") logger.warning(f"CEIDG detail endpoint returned {response.status_code} for id={firma_id}")
except Exception as e: except Exception as e:
logger.warning(f"CEIDG detail fetch failed for id={firma_id}: {e}") logger.warning(f"CEIDG detail fetch failed for id={firma_id}: {e}")