Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null return for payment Methods #1900

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
Loading