omkar-foss commented on code in PR #44220:
URL: https://github.com/apache/airflow/pull/44220#discussion_r1851892723
##########
airflow/api_fastapi/common/types.py:
##########
@@ -59,6 +66,20 @@ class TimeDelta(BaseModel):
TimeDeltaWithValidation = Annotated[TimeDelta,
BeforeValidator(_validate_timedelta_field)]
+def _validate_nonnaive_datetime_field(dt: datetime | None) -> datetime | None:
+ """Validate and return the datetime field."""
+ if dt is None:
+ return None
+ if isinstance(dt, str):
+ dt = datetime.fromisoformat(dt)
+ if not dt.tzinfo:
+ raise ValueError("Invalid datetime format, Naive datetime is
disallowed")
+ return dt
+
+
+DatetimeWithNonNaiveValidation = Annotated[datetime,
BeforeValidator(_validate_nonnaive_datetime_field)]
+
+
Review Comment:
Done, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]