ecerulm edited a comment on issue #16551:
URL: https://github.com/apache/airflow/issues/16551#issuecomment-866466511
> If we coerce the datetime object in `__init__`, we can remove the later
timezone type coercion we have right now.
Yes, and you will get rid of InvalidTimezone at `DAG.following_schedule()`
and `DAG.previous_schedule()` but it will still raise InvalidTimezone on dag
deserialization. So it's actually detrimental to coerce to pendulum.
Just to clarify my point, in the current (pre-PR) codebase if you provide a
pendulum datetime with a non-named pendulum.timezone that will raise
InvalidTimezone in `following_schedule`, `previous_schedule` and in
deserialization:
```
from datetime import datetime,timezone
import pendulum
from airflow.serialization import SerializedDAG
from airflow.models import DAG
start_date = datetime(2021,6,1,tzinfo=timezone.utc)
start_date = pendulum.instance(start_date) # DateTime(2021, 6, 1, 0, 0, 0,
tzinfo=Timezone('+00:00'))
dag = DAG(dag_id='mydag', start_date=start_date, schedule_interval="@hourly")
serialized_dag = SerializedDAG.to_dict(dag)
serialized_dag['dag']['timezone'] # '+00:00'
dag = SerializedDAG.from_dict(serialized_dag) # InvalidTimezone raised here
in deserialization
dag.following_schedule(start_date) # raises InvalidTimezone
dag.previous_schedule(start_date) # raises InvalidTimezone
```
The PR #16599 will get rid of the `InvalidTimezone` in the
`following_schedule`, `previous_schedule` but not really help for the
deserialization case. You still need to provide a serializable/deserializable
datetime as start_date and there are many pendulum datetimes that are not (all
the datetimes with non-named timezones like fixed offsets)
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]