Apache Airflow version: 2.0.2
Kubernetes version (if you are using kubernetes) (use kubectl version):
Environment:
- Cloud provider or hardware configuration:
- OS (e.g. from /etc/os-release):
- Kernel (e.g.
uname -a):
- Install tools:
- Others:
What happened:
In a DAG with datetime(2021, 5, 31, tzinfo=timezone.utc) it will raise an AttributeError: 'datetime.timezone' object has no attribute 'name' in the scheduler.
It seems that airflow relies on the tzinfo object to have a .name attribute so the "canonical" datetime.timezone.utc does not comply with that requirement.
AttributeError: 'datetime.timezone' object has no attribute 'name'
Process DagFileProcessor302-Process:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/local/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 184, in _run_file_processor
result: Tuple[int, int] = dag_file_processor.process_file(
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
return func(*args, session=session, **kwargs)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 648, in process_file
dagbag.sync_to_db()
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
return func(*args, session=session, **kwargs)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dagbag.py", line 556, in sync_to_db
for attempt in run_with_db_retries(logger=self.log):
File "/home/airflow/.local/lib/python3.8/site-packages/tenacity/__init__.py", line 390, in __iter__
do = self.iter(retry_state=retry_state)
File "/home/airflow/.local/lib/python3.8/site-packages/tenacity/__init__.py", line 356, in iter
return fut.result()
File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 437, in result
return self.__get_result()
File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
raise self._exception
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dagbag.py", line 570, in sync_to_db
DAG.bulk_write_to_db(self.dags.values(), session=session)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 67, in wrapper
return func(*args, **kwargs)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dag.py", line 1892, in bulk_write_to_db
orm_dag.calculate_dagrun_date_fields(
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dag.py", line 2268, in calculate_dagrun_date_fields
self.next_dagrun, self.next_dagrun_create_after = dag.next_dagrun_info(most_recent_dag_run)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dag.py", line 536, in next_dagrun_info
next_execution_date = self.next_dagrun_after_date(date_last_automated_dagrun)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dag.py", line 571, in next_dagrun_after_date
next_start = self.following_schedule(now)
File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/dag.py", line 485, in following_schedule
tz = pendulum.timezone(self.timezone.name)
AttributeError: 'datetime.timezone' object has no attribute 'name'
What you expected to happen:
If start_date or any other input parameter requires a tzinfo with a name attribute it should check for that in the DAG object and produce a more specific error message not AttributeError.
Also I guess this requirement should be explicitly mentioned in https://airflow.apache.org/docs/apache-airflow/stable/timezone.html with a comment like
you can't use datetime.timezone.utc because it does not have a name attribute
Or even better it would be not to rely on the presence of a name attribute in the tzinfo....
How to reproduce it:
from datetime import timedelta, datetime, timezone
args = {
"owner": "airflow",
"retries": 3,
}
dag = DAG(
dag_id="xxxx",
default_args=args,
start_date=datetime(2021, 5, 31, tzinfo=timezone.utc),
schedule_interval="0 8 * * *",
max_active_runs=1,
dagrun_timeout=timedelta(minutes=60),
catchup=False,
description="xxxxx",
)
Anything else we need to know:
Apache Airflow version: 2.0.2
Kubernetes version (if you are using kubernetes) (use
kubectl version):Environment:
uname -a):What happened:
In a DAG with
datetime(2021, 5, 31, tzinfo=timezone.utc)it will raise anAttributeError: 'datetime.timezone' object has no attribute 'name'in the scheduler.It seems that airflow relies on the tzinfo object to have a
.nameattribute so the "canonical"datetime.timezone.utcdoes not comply with that requirement.What you expected to happen:
If
start_dateor any other input parameter requires atzinfowith anameattribute it should check for that in the DAG object and produce a more specific error message notAttributeError.Also I guess this requirement should be explicitly mentioned in https://airflow.apache.org/docs/apache-airflow/stable/timezone.html with a comment like
Or even better it would be not to rely on the presence of a
nameattribute in the tzinfo....How to reproduce it:
Anything else we need to know: