1

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': ['airflow@example.com'],
     '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': ['airflow@example.com'], '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': ['airflow@example.com'], '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.

  • "Airflow stores datetime information in UTC internally and in the database. It allows you to run your DAGs with time zone dependent schedules. At the moment, Airflow does not convert them to the end user’s time zone in the user interface. It will always be displayed in UTC there. Also, templates used in Operators are not converted. Time zone information is exposed and it is up to the writer of DAG to decide what do with it." https://airflow.apache.org/docs/apache-airflow/stable/timezone.html – Emma Feb 02 '22 at 19:08

0 Answers0