From c7865f9c90ac549333d16c10e597d22f27439c3a Mon Sep 17 00:00:00 2001 From: Daniel Oronsi Date: Wed, 15 Apr 2026 15:24:54 +0300 Subject: [PATCH] chore: add AlertConflictError when the alert is ambiguous across environments --- CHANGES | 4 ++++ intezer_sdk/__init__.py | 2 +- intezer_sdk/alerts.py | 7 +++++-- intezer_sdk/errors.py | 7 +++++++ tests/unit/test_alerts.py | 11 +++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index bb9bdbd..2f72ccc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.26.0 +------- +- Raise AlertConflictError when fetching an alert by id without an environment returns 409 (previously masked as AlertNotFoundError) + 1.25.1 ------- - Make request method kwargs only and add params diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index 760870c..5fc7041 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.25.1' +__version__ = '1.26.0' diff --git a/intezer_sdk/alerts.py b/intezer_sdk/alerts.py index 0e36b6a..f96ae0a 100644 --- a/intezer_sdk/alerts.py +++ b/intezer_sdk/alerts.py @@ -2,6 +2,7 @@ import hashlib import json import time +from http import HTTPStatus from io import BytesIO from typing import Any from typing import BinaryIO @@ -314,11 +315,12 @@ def check_status(self) -> AlertStatusCode: Refresh the alert data from the Intezer Platform API - overrides current data (if exists) with the new data. :return: The updated status of the alert. - """ try: alert, status = self._api.get_alert_by_alert_id(alert_id=self.alert_id, environment=self.environment) - except requests.HTTPError: + except requests.HTTPError as e: + if e.response is not None and e.response.status_code == HTTPStatus.CONFLICT: + raise errors.AlertConflictError(self.alert_id) self.status = AlertStatusCode.NOT_FOUND raise errors.AlertNotFoundError(self.alert_id) @@ -374,6 +376,7 @@ def from_id(cls, :param timeout: The timeout for the wait operation. :raises intezer_sdk.errors.AlertNotFound: If the alert was not found. :raises intezer_sdk.errors.AlertInProgressError: If the alert is still being processed. + :raises intezer_sdk.errors.AlertConflictError: If the alert is ambiguous across environments and no environment was provided. :return: The Alert instance, with the updated alert data. """ new_alert = cls(alert_id=alert_id, environment=environment or None, api=api) diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index 44ebe9c..a4a460f 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -159,6 +159,13 @@ def __init__(self, alert_id: str): super().__init__(f'The given alert does not exist - {alert_id}') +class AlertConflictError(AlertError): + def __init__(self, alert_id: str): + super().__init__( + f'The alert {alert_id} is ambiguous across environments - please specify an environment' + ) + + class InvalidAlertArgumentError(AlertError): def __init__(self, message: str): super().__init__(message) diff --git a/tests/unit/test_alerts.py b/tests/unit/test_alerts.py index eaee368..18630c3 100644 --- a/tests/unit/test_alerts.py +++ b/tests/unit/test_alerts.py @@ -83,6 +83,17 @@ def test_alert_from_id(self): self.assertEqual(alert.alert_id, 'alert_id') + def test_alert_from_id_raises_conflict_when_environment_is_ambiguous(self): + # Arrange + with responses.RequestsMock() as mock: + mock.add('GET', + url=f'{self.full_url}/alerts/get-by-id', + status=HTTPStatus.CONFLICT, + json={'error': 'Alert exists in multiple environments'}) + # Act & Assert + with self.assertRaises(errors.AlertConflictError): + Alert.from_id('alert_id') + def test_alert_from_id_waits_from_completion(self): # Arrange with responses.RequestsMock() as mock: