Skip to content

Commit

Permalink
Fix null return for payment Methods (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Feb 11, 2025
1 parent 850f0d3 commit 6fe85a0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pay-api/src/pay_api/services/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from flask import current_app
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.sql import func

from pay_api.models.corp_type import CorpType, CorpTypeSchema
from pay_api.models.error_code import ErrorCode, ErrorCodeSchema
Expand Down Expand Up @@ -100,7 +101,7 @@ def find_valid_payment_methods_by_product_code(cls, product_code: str | None = N
"""Find payment methods for a product."""
if not product_code:
corp_types = (
CorpType.query.with_entities(CorpType.product, CorpType.payment_methods)
CorpType.query.with_entities(CorpType.product, func.coalesce(CorpType.payment_methods, []))
.filter(CorpType.product.isnot(None)) # Exclude None at the query level
.distinct()
.all()
Expand All @@ -112,4 +113,4 @@ def find_valid_payment_methods_by_product_code(cls, product_code: str | None = N
.filter_by(product=product_code)
.first()
)
return {corp_type.product: corp_type.payment_methods} if corp_type else {}
return {corp_type.product: corp_type.payment_methods or []} if corp_type else {}

0 comments on commit 6fe85a0

Please sign in to comment.