Skip to content

Commit

Permalink
fix: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii committed Jan 1, 2025
1 parent bc2cfb9 commit 7801a4b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
19 changes: 12 additions & 7 deletions commerce_coordinator/apps/commercetools/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def update_line_item_transition_state_on_fulfillment(
handle_commercetools_error(err, f"Unable to update LineItemState of order {order_id}", True)
return None

def update_all_line_items_transition_state_on_fulfillment(
def update_line_items_transition_state(
self,
order_id: str,
order_version: int,
Expand All @@ -644,8 +644,10 @@ def update_all_line_items_transition_state_on_fulfillment(
from_state_key = self.get_state_by_id(from_state_id).key

logger.info(
f"[CommercetoolsAPIClient] - Transitioning all line item states for order with ID {order_id} "
f"from {from_state_key} to {new_state_key}"
f"[CommercetoolsAPIClient] - Transitioning line item states for order ID '{order_id}'. "
f"From State: '{from_state_key}' "
f"To State: '{new_state_key}' "
f"Line Item IDs: {', '.join(item.id for item in line_items)}"
)

try:
Expand All @@ -660,13 +662,11 @@ def update_all_line_items_transition_state_on_fulfillment(
for item in line_items
]

updated_fulfillment_line_item_order = self.base_client.orders.update_by_id(
return self.base_client.orders.update_by_id(
id=order_id,
version=order_version,
actions=actions,
)

return updated_fulfillment_line_item_order
else:
logger.info(
f"All line items already have the correct state {new_state_key}. "
Expand All @@ -675,7 +675,12 @@ def update_all_line_items_transition_state_on_fulfillment(
return self.get_order_by_id(order_id)

Check failure on line 675 in commerce_coordinator/apps/commercetools/clients.py

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, 3.12, django42)

Missing coverage

Missing coverage on lines 671-675
except CommercetoolsError as err:
# Logs & ignores version conflict errors due to duplicate Commercetools messages
handle_commercetools_error(err, f"Unable to update all LineItemStates of order {order_id}", True)
handle_commercetools_error(
err,
f"Failed to update LineItemStates for order ID '{order_id}'. "
f"Line Item IDs: {', '.join(item.id for item in line_items)}",
True
)
return None

def retire_customer_anonymize_fields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def fulfill_order_placed_message_signal_task(
logger.info(
f"[CT-{tag}] Transitioning all line items for order {order.id} to {TwoUKeys.PROCESSING_FULFILMENT_STATE}"
)
updated_order = client.update_all_line_items_transition_state_on_fulfillment(
updated_order = client.update_line_items_transition_state(
order_id=order.id,
order_version=order.version,
line_items=get_edx_items(order),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, *args, **kwargs):
self.get_state_by_key = self.state_by_key_mock
self.get_payment_by_key = self.payment_mock
self.update_line_item_transition_state_on_fulfillment = self.updated_line_item_mock
self.update_all_line_items_transition_state_on_fulfillment = self.updated_line_item_mock
self.update_line_items_transition_state = self.updated_line_item_mock
self.create_return_for_order = self.create_return_item_mock
self.create_return_payment_transaction = self.payment_mock
self.update_return_payment_state_after_successful_refund = self.order_mock
Expand Down
8 changes: 4 additions & 4 deletions commerce_coordinator/apps/commercetools/tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def test_successful_order_all_line_items_state_update(self, mock_state_by_id):
status_code=200
)

result = self.client_set.client.update_all_line_items_transition_state_on_fulfillment(
result = self.client_set.client.update_line_items_transition_state(
mock_order.id,
mock_order.version,
mock_order.line_items,
Expand Down Expand Up @@ -754,7 +754,7 @@ def test_update_all_line_items_state_exception(self, mock_state_by_id):
)

with patch('commerce_coordinator.apps.commercetools.clients.logging.Logger.info') as log_mock:
self.client_set.client.update_all_line_items_transition_state_on_fulfillment(
self.client_set.client.update_line_items_transition_state(
mock_order.id,
mock_order.version,
mock_order.line_items,
Expand All @@ -763,8 +763,8 @@ def test_update_all_line_items_state_exception(self, mock_state_by_id):
)

expected_message = (
f"[CommercetoolsError] Unable to update all LineItemStates "
f"of order mock_order_id "
f"[CommercetoolsError] Failed to update LineItemStates "
f"for order ID 'mock_order_id'. Line Item IDs: {mock_order.line_items[0].id} "
f"- Correlation ID: {mock_error_response['correlation_id']}, "
f"Details: {mock_error_response['errors']}"
)
Expand Down

0 comments on commit 7801a4b

Please sign in to comment.