Skip to content

Commit 55a219d

Browse files
jeremiclaude
andcommitted
refactor(spp_dci_client_dr): route callback envelope unwrap through dr_parsing
The callback path duplicated `data.get("reg_records", [])` without the type guards and WARN logging now centralized in `unwrap_search_data`. A malformed `data` envelope was silently coerced to `{}` and skipped, hiding spec drift from operators. Route through the shared helper so both sync and callback paths get identical validation behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8632ae1 commit 55a219d

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

spp_dci_client_dr/routers/callback.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from fastapi import APIRouter, Depends, HTTPException, Request, status
1616

1717
from ..middleware.signature import verify_dr_signature
18-
from ..services.dr_parsing import extract_disability_data
18+
from ..services.dr_parsing import extract_disability_data, unwrap_search_data
1919

2020
_logger = logging.getLogger(__name__)
2121

@@ -151,8 +151,7 @@ def _process_dr_search_result(env: Environment, result: dict, source_registry: s
151151
)
152152
return
153153

154-
data = result.get("data", {})
155-
reg_records = data.get("reg_records", [])
154+
reg_records = unwrap_search_data(result.get("data"))
156155

157156
for record in reg_records:
158157
# Extract identifiers to find matching partner

spp_dci_client_dr/tests/test_callback.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ def test_non_success_status_is_skipped(self):
166166
self.assertEqual(len(status), 0)
167167
mock_find.assert_not_called()
168168

169+
def test_malformed_envelope_warns_and_does_not_crash(self):
170+
"""`data` of an unexpected type is rejected by unwrap_search_data with a WARN
171+
rather than crashing the callback or silently processing garbage."""
172+
from odoo.addons.spp_dci_client_dr.routers.callback import _process_dr_search_result
173+
174+
result = {
175+
"status": "succ",
176+
"data": "not-an-envelope",
177+
}
178+
179+
with (
180+
patch(
181+
"odoo.addons.spp_dci_client_dr.routers.callback._find_partner_by_identifier",
182+
) as mock_find,
183+
self.assertLogs("odoo.addons.spp_dci_client_dr.services.dr_parsing", level="WARNING"),
184+
):
185+
_process_dr_search_result(self.env, result, "test-source-registry")
186+
187+
mock_find.assert_not_called()
188+
169189
def test_update_overwrites_existing_record(self):
170190
"""Calling _process_dr_search_result twice updates the existing record."""
171191
from odoo.addons.spp_dci_client_dr.routers.callback import _process_dr_search_result

0 commit comments

Comments
 (0)