ashb commented on code in PR #45030:
URL: https://github.com/apache/airflow/pull/45030#discussion_r1890267714
##########
airflow/api_fastapi/execution_api/datamodels/taskinstance.py:
##########
@@ -83,6 +83,15 @@ class TIDeferredStatePayload(BaseModel):
next_method: str
trigger_timeout: timedelta | None = None
+ @field_validator("trigger_kwargs", mode="before")
+ def validate_moment(cls, v):
+ from datetime import datetime
+
+ if "moment" in v and isinstance(v["moment"], str):
+ moment = datetime.fromisoformat(v["moment"].replace("Z", "+00:00"))
+ v["moment"] = moment
+ return v
Review Comment:
And we should use Pydantic's AwareDateTime:
```python
In [7]:
pydantic.TypeAdapter(pydantic.AwareDatetime).validate_strings("2020-01-02T13:10:59.123Z")
Out[7]: datetime.datetime(2020, 1, 2, 13, 10, 59, 123000, tzinfo=TzInfo(UTC))
In [8]:
pydantic.TypeAdapter(pydantic.AwareDatetime).validate_strings("2020-01-02T13:10:59.123")
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[8], line 1
----> 1
pydantic.TypeAdapter(pydantic.AwareDatetime).validate_strings("2020-01-02T13:10:59.123")
File
~/code/airflow/airflow/.venv/lib/python3.12/site-packages/pydantic/type_adapter.py:474,
in TypeAdapter.validate_strings(self, obj, strict, context,
experimental_allow_partial)
450 def validate_strings(
451 self,
452 obj: Any,
(...)
457 experimental_allow_partial: bool | Literal['off', 'on',
'trailing-strings'] = False,
458 ) -> T:
459 """Validate object contains string data against the model.
460
461 Args:
(...)
472 The validated object.
473 """
--> 474 return self.validator.validate_strings(
475 obj, strict=strict, context=context,
allow_partial=experimental_allow_partial
476 )
ValidationError: 1 validation error for datetime
Input should have timezone info [type=timezone_aware,
input_value='2020-01-02T13:10:59.123', input_type=str]
For further information visit
https://errors.pydantic.dev/2.10/v/timezone_aware
```
--
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]