diff --git a/VERSION b/VERSION index 1e71de9..ad0b729 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.29 +2.3.30 diff --git a/app/modules/invoice_error_finder/services/detection_service.py b/app/modules/invoice_error_finder/services/detection_service.py index 3802ffa..cbd8fd6 100644 --- a/app/modules/invoice_error_finder/services/detection_service.py +++ b/app/modules/invoice_error_finder/services/detection_service.py @@ -628,10 +628,15 @@ class DetectionService: @staticmethod def _resolve_hub_customer_id(row: Dict[str, Any]) -> Optional[int]: - value = row.get("hub_customer_id") or row.get("customer_key") - if isinstance(value, int): - return value - return None + value = row.get("hub_customer_id") + if not isinstance(value, int): + return None + + customer = execute_query_single( + "SELECT id FROM customers WHERE id = %s", + (value,), + ) + return value if customer else None @staticmethod def _resolve_customer_name(hub_customer_id: Optional[int], fallback: Optional[str]) -> Optional[str]: diff --git a/tests/test_invoice_error_finder.py b/tests/test_invoice_error_finder.py index 0c82ee8..08490ab 100644 --- a/tests/test_invoice_error_finder.py +++ b/tests/test_invoice_error_finder.py @@ -179,6 +179,30 @@ def test_detection_service_reopens_expired_ignored_issue(monkeypatch): assert "ignored_until = NULL" in updates[0][0] +def test_detection_service_ignores_non_hub_customer_keys(monkeypatch): + from app.modules.invoice_error_finder.services.detection_service import DetectionService + + def fake_execute_query_single(query, params=None): + if "SELECT id FROM customers" in query: + return None + return None + + monkeypatch.setattr( + "app.modules.invoice_error_finder.services.detection_service.execute_query_single", + fake_execute_query_single, + ) + + service = DetectionService() + customer_id = service._resolve_hub_customer_id( + { + "customer_key": 56283338, + "hub_customer_id": None, + } + ) + + assert customer_id is None + + def test_list_issues_supports_unassigned_filter(monkeypatch): from app.modules.invoice_error_finder.backend.router import list_issues