diff --git a/pay-api/src/pay_api/services/code.py b/pay-api/src/pay_api/services/code.py index d6b3e1058..355fef197 100644 --- a/pay-api/src/pay_api/services/code.py +++ b/pay-api/src/pay_api/services/code.py @@ -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 @@ -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() @@ -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 {}