diff --git a/commerce_coordinator/apps/commercetools/clients.py b/commerce_coordinator/apps/commercetools/clients.py index 0ceb13e2..09a0abac 100644 --- a/commerce_coordinator/apps/commercetools/clients.py +++ b/commerce_coordinator/apps/commercetools/clients.py @@ -582,7 +582,7 @@ def update_line_item_transition_state_on_fulfillment(self, order_id: str, order_ return self.get_order_by_id(order_id) except CommercetoolsError as err: # Logs & ignores version conflict errors due to duplicate Commercetools messages - handle_commercetools_error(err, f"Unable to update LineItemState of order {order_id}") + handle_commercetools_error(err, f"Unable to update LineItemState of order {order_id}", True) return None def retire_customer_anonymize_fields(self, customer_id: str, customer_version: int, diff --git a/commerce_coordinator/apps/commercetools/sub_messages/tasks.py b/commerce_coordinator/apps/commercetools/sub_messages/tasks.py index 4ccdcddb..e244ddbd 100644 --- a/commerce_coordinator/apps/commercetools/sub_messages/tasks.py +++ b/commerce_coordinator/apps/commercetools/sub_messages/tasks.py @@ -104,6 +104,8 @@ def fulfill_order_placed_message_signal_task( line_item_state_id, TwoUKeys.PROCESSING_FULFILMENT_STATE ) + if not updated_order: + return True # from here we will always be transitioning from a 'Fulfillment Processing' state line_item_state_id = client.get_state_by_key(TwoUKeys.PROCESSING_FULFILMENT_STATE).id diff --git a/commerce_coordinator/apps/commercetools/tests/test_clients.py b/commerce_coordinator/apps/commercetools/tests/test_clients.py index 1e66b5d7..ff17e316 100644 --- a/commerce_coordinator/apps/commercetools/tests/test_clients.py +++ b/commerce_coordinator/apps/commercetools/tests/test_clients.py @@ -672,7 +672,7 @@ def test_update_line_item_state_exception(self, mock_state_by_id): status_code=409 ) - with patch('commerce_coordinator.apps.commercetools.clients.logging.Logger.error') as log_mock: + with patch('commerce_coordinator.apps.commercetools.clients.logging.Logger.info') as log_mock: self.client_set.client.update_line_item_transition_state_on_fulfillment( "mock_order_id", 1, @@ -689,7 +689,7 @@ def test_update_line_item_state_exception(self, mock_state_by_id): f"Details: {mock_error_response['errors']}" ) - log_mock.assert_called_once_with(expected_message) + log_mock.assert_called_with(expected_message) @patch('commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient.get_state_by_id') @patch('commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient.get_order_by_id') diff --git a/commerce_coordinator/apps/commercetools/utils.py b/commerce_coordinator/apps/commercetools/utils.py index 01116d09..8f4f6ca6 100644 --- a/commerce_coordinator/apps/commercetools/utils.py +++ b/commerce_coordinator/apps/commercetools/utils.py @@ -35,9 +35,13 @@ def get_braze_client(): ) -def handle_commercetools_error(err: CommercetoolsError, context: str): +def handle_commercetools_error(err: CommercetoolsError, context: str, is_info=False): + """Handles commercetools errors.""" error_message = f"[CommercetoolsError] {context} - Correlation ID: {err.correlation_id}, Details: {err.errors}" - logger.error(error_message) + if is_info: + logger.info(error_message) + else: + logger.error(error_message) def send_order_confirmation_email(