Airflow - Wrong timestamp inside DAG default_args

538 views Asked by At

Airflow version 2.1.0 / Python version 3.6

Hello.

I've realized whenever I try to create and schedule a DAG to run at a specific time in the day, the timestamp value is reset to UTC. I've noticed a strange behavior between the default_args and the default_args after imported inside the DAG

The example below was created to reproduce the behaviour:

import pendulum
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta

local_tz=pendulum.timezone("America/Sao_Paulo")

default_args = {
     'owner': 'airflow',
     'start_date': datetime(2022, 2, 2, tzinfo=local_tz),
     'depends_on_past': False,
     'email': ['[email protected]'],
     'email_on_failure': False,
     'email_on_retry': False,
     'retries': 1,
     'retry_delay': timedelta(seconds=30)
}

dag = DAG(
     dag_id='dag-test',
     default_args=default_args,
     tags=['pdi', 'airflow', 'carte'],
     schedule_interval='0 15 * * *')

As expected, if I print the content of default_args, we can see tzinfo is correctly set to: Timezone('America/Sao_Paulo')

print(default_args)
{'owner': 'airflow', 'start_date': datetime.datetime(2022, 2, 2, 0, 0, tzinfo=Timezone('America/Sao_Paulo')), 'depends_on_past': False, 'email': ['[email protected]'], 'email_on_failure': False, 'email_on_retry': False, 'retries': 1, 'retry_delay': datetime.timedelta(seconds=30)}

Now, for some reason I can't figure it out why, if we print the default_args inside the DAG, we can see that tzinfo turns into tzinfo=Timezone('UTC') even though it's using the same arguments.

print(dag.default_args)
{'owner': 'airflow', 'start_date': datetime.datetime(2022, 2, 2, 3, 0, tzinfo=Timezone('UTC')), 'depends_on_past': False, 'email': ['[email protected]'], 'email_on_failure': False, 'email_on_retry': False, 'retries': 1, 'retry_delay': datetime.timedelta(seconds=30)}

I don't understand this behavior, can you help me? Thank you in advance.

0

There are 0 answers