fix: use SQL func.replace instead of Python str.replace on column
Some checks failed
CI / ruff (push) Successful in 10s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has started running

LoyaltyCard.card_number is a SQLAlchemy column, not a string —
cannot call .replace() on it. Use func.replace() for the SQL query.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 22:12:49 +01:00
parent 1194731f33
commit c9b2ecbdff

View File

@@ -63,13 +63,15 @@ class CardService:
def get_card_by_number(self, db: Session, card_number: str) -> LoyaltyCard | None: def get_card_by_number(self, db: Session, card_number: str) -> LoyaltyCard | None:
"""Get a loyalty card by card number.""" """Get a loyalty card by card number."""
# Normalize card number (remove dashes) from sqlalchemy import func
# Normalize card number (remove dashes/spaces)
normalized = card_number.replace("-", "").replace(" ", "") normalized = card_number.replace("-", "").replace(" ", "")
return ( return (
db.query(LoyaltyCard) db.query(LoyaltyCard)
.options(joinedload(LoyaltyCard.program)) .options(joinedload(LoyaltyCard.program))
.filter( .filter(
LoyaltyCard.card_number.replace("-", "") == normalized func.replace(func.replace(LoyaltyCard.card_number, "-", ""), " ", "") == normalized
) )
.first() .first()
) )