Merge pull request 'fix(api): 修复验证码repository datetime时区问题 - naive转aware' (#755) from fix/verification-code-datetime-timezone into develop
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled

This commit was merged in pull request #755.
This commit is contained in:
2026-07-23 17:32:51 +08:00
@@ -67,13 +67,24 @@ class SQLAlchemyVerificationCodeRepository(VerificationCodeRepository):
def _to_entity(model: VerificationCodeModel | None) -> VerificationCode | None:
if model is None:
return None
# SQLAlchemy 从数据库读出的 DateTime 是 naive(不带时区),
# 领域模型期望 aware datetime(带 timezone.utc),直接用会报
# "can't compare offset-naive and offset-aware datetimes"
def _ensure_aware(dt: datetime | None) -> datetime | None:
if dt is None:
return None
if dt.tzinfo is None:
return dt.replace(tzinfo=timezone.utc)
return dt
return VerificationCode(
id=model.id,
recipient=model.recipient,
code=model.code,
code_type=model.code_type,
expires_at=model.expires_at,
used_at=model.used_at,
expires_at=_ensure_aware(model.expires_at),
used_at=_ensure_aware(model.used_at),
attempts=model.attempts,
created_at=model.created_at,
created_at=_ensure_aware(model.created_at),
)