henry3260 commented on issue #60408: URL: https://github.com/apache/airflow/issues/60408#issuecomment-3744853398
> Hi [@henry3260](https://github.com/henry3260) , thanks for working on this. Any idea why passing in a `datetime` object results in a `str` being serialized here? My expectation is that the datetime should be serialized as a json dict with `{ "timestamp": 123456789, "tz": "utc" }` and not a string? I agree! Let me clarify the issue: **The root cause is not about serialization** - the serialization part is working correctly. When a `datetime` object is serialized, it's properly encoded as `{"__type": "datetime", "__var": timestamp}`. When using `TriggerDagRunOperator.partial(logical_date="{{ ts_nodash_with_tz }}")`, the `logical_date` parameter is set to a **template string**, not a datetime object. This is valid because `logical_date` is in the operator's `template_fields`. However, during deserialization via `_deserialize_partial_kwargs` → `_deserialize_field_value`, the code sees that the field name ends with `_date` and assumes it must be a datetime value, so it calls `_deserialize_datetime(value)` - but `value` is actually a template string like `"{{ ts_nodash_with_tz }}"`. The original `_deserialize_datetime` method only handled numeric timestamps (int/float), causing the error: ```python TypeError: 'str' object cannot be interpreted as an integer ``` **My fix** adds a type check in `_deserialize_datetime`: - If the value is a **string** (template or other string representation) → return it as-is for later template rendering - If the value is a **number** (timestamp) → deserialize it to a datetime object as before WDYT? -- 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]
