Skip to content

Commit 39c3452

Browse files
committed
fix: if PastOrToday validator receives a naive datetime, compare to current time without timezone info
This commit updates the `past_or_today_validator` function to handle naive datetimes (those without timezone information) by comparing them to the current time without timezone info. This allows the validator to work correctly with both aware and naive datetimes, ensuring that it can validate past or present datetimes regardless of their timezone awareness.
1 parent 8567db7 commit 39c3452

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

schemas/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class BaseUpdateModel(BaseCreateModel):
5555

5656
def past_or_today_validator(value: date | datetime) -> date | datetime:
5757
if isinstance(value, datetime):
58-
if value > datetime.now(timezone.utc):
58+
if value.tzinfo is None:
59+
if value > datetime.now():
60+
raise ValueError("Datetime must be in the past or present.")
61+
elif value > datetime.now(timezone.utc):
5962
raise ValueError("Datetime must be in the past or present.")
6063
elif value > date.today():
6164
raise ValueError("Date must be today or in the past.")

0 commit comments

Comments
 (0)