'Airflow end_date error AttributeError: 'tuple' object has no attribute 'utcoffset'
I want to add an end_date to my DAG however, when I run the specific DAG I get the above error. It seems odd because I can update the startdate in the same format but not the enddate.
Here is a sample of my code below.
default_args = base_args.copy()
default_args['end_date'] = datetime(2020, 5, 5)
dag = DAG(
dag_name,
catchup=True,
default_args=default_args,
schedule_interval=schedule_interval
)
with dag:
extract = BashOperator(
task_id=dag_name
)
And here is the Traceback
Traceback (most recent call last):
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/models/__init__.py", line 413, in process_file
m = imp.load_source(mod_name, filepath)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/stevepak/Desktop/airflow/Dags/braintree/braintree_transactions_v3.py", line 40, in <module>
schedule_interval=schedule_interval
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/models/__init__.py", line 3087, in __init__
timezone.convert_to_utc(self.default_args['end_date'])
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/utils/timezone.py", line 92, in convert_to_utc
if not is_localized(value):
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/utils/timezone.py", line 38, in is_localized
return value.utcoffset() is not None
AttributeError: 'tuple' object has no attribute 'utcoffset'
Traceback (most recent call last):
File "/Users/steve/.virtualenvs/airflow/bin/airflow", line 32, in <module>
args.func(args)
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/utils/cli.py", line 74, in wrapper
return f(*args, **kwargs)
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/bin/cli.py", line 647, in test
dag = dag or get_dag(args)
File "/Users/steve/.virtualenvs/airflow/lib/python3.7/site-packages/airflow/bin/cli.py", line 145, in get_dag
'parse.'.format(args.dag_id))
Solution 1:[1]
Some extra comma in the code creates this. Especially in the following line:
Before fix:
import pendulum
local_tz = pendulum.timezone("America/Los_Angeles")
date = datetime(2021, 8, 3, tzinfo=local_tz),
Had similar issue. It was extra "," that was creating the issue.
After Fix:
import pendulum
local_tz = pendulum.timezone("America/Los_Angeles")
date = datetime(2021, 8, 3, tzinfo=local_tz)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
