mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 17:13:42 +00:00
fix: resolve TypeError in disclosure revoke due to naive/aware datetime comparison
PyMySQL returns naive datetimes from MySQL DATETIME columns, but revoke_disclosure() compared them with timezone-aware datetime.now(timezone.utc), causing an unhandled TypeError (not caught by except ValueError) and a 500 error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
95e84a6978
commit
1bedbcf243
1 changed files with 7 additions and 2 deletions
|
|
@ -113,6 +113,11 @@ def review_disclosure_request(
|
||||||
return dr
|
return dr
|
||||||
|
|
||||||
|
|
||||||
|
def _utcnow_naive() -> datetime:
|
||||||
|
"""Return current UTC time as a naive datetime, matching MySQL DATETIME columns."""
|
||||||
|
return datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
|
|
||||||
|
|
||||||
def revoke_disclosure(db: Session, request_id: int, user_id: int, *, admin: bool = False) -> DisclosureRequest:
|
def revoke_disclosure(db: Session, request_id: int, user_id: int, *, admin: bool = False) -> DisclosureRequest:
|
||||||
"""Revoke an active disclosure by setting expires_at to now.
|
"""Revoke an active disclosure by setting expires_at to now.
|
||||||
|
|
||||||
|
|
@ -124,12 +129,12 @@ def revoke_disclosure(db: Session, request_id: int, user_id: int, *, admin: bool
|
||||||
raise ValueError("Disclosure request not found")
|
raise ValueError("Disclosure request not found")
|
||||||
if dr.status != "approved":
|
if dr.status != "approved":
|
||||||
raise ValueError("Only approved disclosures can be revoked")
|
raise ValueError("Only approved disclosures can be revoked")
|
||||||
if dr.expires_at and dr.expires_at <= datetime.now(timezone.utc):
|
if dr.expires_at and dr.expires_at <= _utcnow_naive():
|
||||||
raise ValueError("Disclosure already expired")
|
raise ValueError("Disclosure already expired")
|
||||||
if not admin and dr.requester_id != user_id:
|
if not admin and dr.requester_id != user_id:
|
||||||
raise ValueError("Not authorized to revoke this disclosure")
|
raise ValueError("Not authorized to revoke this disclosure")
|
||||||
|
|
||||||
dr.expires_at = datetime.now(timezone.utc)
|
dr.expires_at = _utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(dr)
|
db.refresh(dr)
|
||||||
return dr
|
return dr
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue