Skip to content

Commit

Permalink
return empty Customer object instead of None
Browse files Browse the repository at this point in the history
  • Loading branch information
djnakabaale committed Jan 6, 2025
1 parent 0b23289 commit 09aab51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions koku/koku/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def create_customer(account, org_id, request_method):
org_id (str): The org_id identifier.
request_method (str): The HTTP request method.
Returns:
Customer | None: The created or retrieved customer, or None if not found.
Customer : The created or retrieved customer, or empty customer object if not found.
"""
try:
with transaction.atomic():
Expand All @@ -270,8 +270,8 @@ def create_customer(account, org_id, request_method):
try:
customer = Customer.objects.filter(org_id=org_id).get()
except Customer.DoesNotExist:
LOG.warning(f"Customer for org_id {org_id} does not exist. Returning None.")
return None
LOG.warning(f"Customer for org_id {org_id} does not exist. Returning empty object.")
customer = Customer(account_id="", org_id="", schema_name="")

return customer

Expand Down
3 changes: 2 additions & 1 deletion koku/koku/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ def test_create_customer_integrity_error_customer_does_not_exist(self, mock_save

customer = IdentityHeaderMiddleware.create_customer("test_account", "test_org", "POST")

self.assertIsNone(customer)
self.assertIsNotNone(customer)
self.assertEqual(customer.org_id, "")
mock_save.assert_called_once()
mock_filter.assert_called_once_with(org_id="test_org")
mock_query_set.get.assert_called_once()
Expand Down

0 comments on commit 09aab51

Please sign in to comment.