1
0
mirror of https://github.com/quay/quay.git synced 2026-01-29 08:42:15 +03:00

Use list comprehension in model and expect to return None if no rows are

returned
This commit is contained in:
Marcus Kok
2024-05-09 10:37:05 -04:00
parent 87a8dbfaf9
commit 00c4d37329
2 changed files with 9 additions and 4 deletions

View File

@@ -8,9 +8,14 @@ logger = logging.getLogger(__name__)
def get_web_customer_ids(user_id):
try:
customer_ids = []
for customer in RedHatSubscriptions.select().where(RedHatSubscriptions.user_id == user_id):
customer_ids.append(customer.account_number)
customer_ids = [
customer.account_number
for customer in RedHatSubscriptions.select().where(
RedHatSubscriptions.user_id == user_id
)
]
if len(customer_ids) == 0:
return None
return customer_ids
except RedHatSubscriptions.DoesNotExist:
return None

View File

@@ -23,7 +23,7 @@ class RedHatUserApi(object):
def get_account_number(self, user):
email = user.email
account_numbers = entitlements.get_web_customer_ids(user.id)
if len(account_numbers) == 0:
if account_numbers is None:
account_numbers = self.lookup_customer_id(email)
if account_numbers:
# store in database for next lookup