cansjt opened a new issue #20055:
URL: https://github.com/apache/airflow/issues/20055
### Apache Airflow version
2.2.2 (latest released)
### Operating System
Debian
### Versions of Apache Airflow Providers
N/A
### Deployment
Other 3rd-party Helm chart
### Deployment details
N/A
### What happened
After upgrading from 2.1.3 to 2.2.2, Airflow is no longer capable of
serializing some dags. It fails with the exception:
```
Traceback (most recent call last):
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 817, in serialize_dag
serialize_dag = cls.serialize_to_json(dag, cls._decorated_fields)
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 269, in serialize_to_json
serialized_object[key] = _encode_timetable(value)
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 151, in _encode_timetable
return {\"__type\": importable_string, \"__var\": var.serialize()}
File
\"/usr/local/lib/python3.9/site-packages/airflow/timetables/interval.py\", line
155, in serialize
return {\"expression\": self._expression, \"timezone\":
encode_timezone(self._timezone)}
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 116, in encode_timezone
raise ValueError(f\"DAG timezone should be a pendulum.tz.Timezone, not
{var!r}\")
ValueError: DAG timezone should be a pendulum.tz.Timezone, not
datetime.timezone.utc
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File \"/usr/local/lib/python3.9/site-packages/airflow/models/dagbag.py\",
line 591, in _serialize_dag_capturing_errors
dag_was_updated = SerializedDagModel.write_dag(
File \"/usr/local/lib/python3.9/site-packages/airflow/utils/session.py\",
line 67, in wrapper
return func(*args, **kwargs)
File
\"/usr/local/lib/python3.9/site-packages/airflow/models/serialized_dag.py\",
line 136, in write_dag
new_serialized_dag = cls(dag)
File \"<string>\", line 4, in __init__
File \"/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state.py\",
line 433, in _initialize_instance
manager.dispatch.init_failure(self, args, kwargs)
File
\"/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py\", line
68, in __exit__
compat.raise_(
File \"/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py\",
line 182, in raise_
raise exception
File \"/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state.py\",
line 430, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File
\"/usr/local/lib/python3.9/site-packages/airflow/models/serialized_dag.py\",
line 95, in __init__
self.data = SerializedDAG.to_dict(dag)
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 935, in to_dict
json_dict = {\"__version\": cls.SERIALIZER_VERSION, \"dag\":
cls.serialize_dag(var)}
File
\"/usr/local/lib/python3.9/site-packages/airflow/serialization/serialized_objects.py\",
line 847, in serialize_dag
raise SerializationError(f'Failed to serialize DAG {dag.dag_id!r}: {e}')
airflow.exceptions.SerializationError: Failed to serialize DAG
'preview_meta_eventad_registrations': DAG timezone should be a
pendulum.tz.Timezone, not datetime.timezone.utc
```
The start date was provide to the DAG initializer as
`datetime.datetime(2020, 11, 1, 0, 0, tzinfo=datetime.timezone.utc)`, which,
FYI, is the result of the parsing of a YAML file.
### What you expected to happen
Airflow should be capable of serializing the DAG without any error.
### How to reproduce
Create ad DAG with a start date as follows:
```python_naive_dag_defaults
from datetime import datetime, timezone
from airflow.models import DAG
DAG('whatever', start_date=datetime(2021,12,5, 0, 0, 0, tzinfo=timezone.utc,
...)
```
And enable DAG serialization in Airflow's configuration (though this is the
default now, no more `store_serialized_dags` option in the configuration
reference).
### Anything else
This is similar but yet slightly different from apache/airflow#16613.
May also be related to apache/airflow#19450.
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]