Skip to content

Commit

Permalink
Merge pull request #277 from openedx/pwnage101/ENT-9133-2
Browse files Browse the repository at this point in the history
fix: null metadata should just be tolerated
  • Loading branch information
pwnage101 authored Jul 22, 2024
2 parents 95e5903 + 18f674e commit b088dfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion enterprise_subsidy/apps/api/v2/serializers/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def create(self, validated_data):
sales_contract_reference_id=validated_data['sales_contract_reference_id'],
sales_contract_reference_provider=validated_data['sales_contract_reference_provider'],
idempotency_key=validated_data.get('idempotency_key'),
**validated_data.get('metadata', {}),
**(validated_data.get('metadata') or {}),
)
except openedx_ledger.api.DepositCreationError as exc:
logger.error(
Expand Down
13 changes: 12 additions & 1 deletion enterprise_subsidy/apps/api/v2/tests/test_deposit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class DepositCreateViewTests(APITestMixin):
},
"expected_response_status": status.HTTP_201_CREATED,
},
{
"subsidy_active": True,
"creation_request_data": {
"desired_deposit_quantity": 100,
"sales_contract_reference_id": str(uuid.uuid4()),
"sales_contract_reference_provider": DEFAULT_SALES_CONTRACT_REFERENCE_PROVIDER_SLUG,
# Test getting a null metadata value.
"metadata": None,
},
"expected_response_status": status.HTTP_201_CREATED,
},
###
# Sad paths:
Expand Down Expand Up @@ -119,7 +130,7 @@ def test_deposit_creation(
creation_request_data["sales_contract_reference_provider"]
assert Deposit.objects.count() == 2
created_deposit = Deposit.objects.get(uuid=response.data["uuid"])
assert created_deposit.transaction.metadata == creation_request_data.get("metadata", {})
assert created_deposit.transaction.metadata == (creation_request_data.get("metadata") or {})
else:
assert Deposit.objects.count() == 1

Expand Down

0 comments on commit b088dfb

Please sign in to comment.