You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2019/05/14 03:01:00 UTC

[jira] [Commented] (AIRFLOW-4510) Timezone set incorrectly if multiple DAGs defined in the same file

    [ https://issues.apache.org/jira/browse/AIRFLOW-4510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16839041#comment-16839041 ] 

ASF GitHub Bot commented on AIRFLOW-4510:
-----------------------------------------

abhishekray07 commented on pull request #5277: [AIRFLOW-4510] Don't mutate default_args during DAG initialization
URL: https://github.com/apache/airflow/pull/5277
 
 
   While initializing a DAG, default_args is being mutated. If another
   DAG is created in the same file with the same default_args, it gets
   initialized with the incorrect Timezone information.
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following [Airflow Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR"
     - https://issues.apache.org/jira/browse/AIRFLOW-XXX
     - In case you are fixing a typo in the documentation you can prepend your commit with \[AIRFLOW-XXX\], code changes always need a Jira issue.
     - In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)).
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI changes:
   
   ### Tests
   
   - [x] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [x ] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain docstrings that explain what it does
     - If you implement backwards incompatible changes, please leave a note in the [Updating.md](https://github.com/apache/airflow/blob/master/UPDATING.md) so we can assign it to a appropriate release
   
   ### Code Quality
   
   - [x ] Passes `flake8`
   
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Timezone set incorrectly if multiple DAGs defined in the same file
> ------------------------------------------------------------------
>
>                 Key: AIRFLOW-4510
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-4510
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: DAG
>    Affects Versions: 1.10.3
>            Reporter: Abhishek Ray
>            Assignee: Abhishek Ray
>            Priority: Major
>         Attachments: Screen Shot 2019-05-13 at 2.41.54 PM.png, Screen Shot 2019-05-13 at 6.45.25 PM.png
>
>
> If multiple DAGs are defined in the same file and they share the same default_args, then the subsequent DAGs have an incorrect timezone.
>  
> Steps to reproduce:
>  
> Set the default_timezone to be non-UTC in airflow.cfg
>  
> {noformat}
> default_timezone = America/New_York{noformat}
>  
> DAG definition which has multiple DAGs in the same file:
>  
>  
> {code:java}
> from airflow import DAG
> from airflow.operators.bash_operator import BashOperator
> from datetime import datetime, timedelta
> default_args = {
>  'owner': 'airflow',
>  'depends_on_past': False,
>  'start_date': datetime(2019, 5, 11),
> }
> def make_dynamic_dag(schedule_interval, dag_name):
>  dag = DAG(f"tutorial_{dag_name}", default_args=default_args, schedule_interval=schedule_interval)
>  t1 = BashOperator(task_id='print_date', bash_command='date', dag=dag)
>  return dag
> test_dag_1 = make_dynamic_dag("00 15 * * *", “1”)
> test_dag_2 = make_dynamic_dag("00 18 * * *", “2”)
> {code}
>  
>  
> test_dag_1 is expected to run at 15:00 EST or 19:00 UTC and test_dag_2 is expected to run at 18:00 EST or 22:00 UTC.
>  
> However, test_dag_2 runs at 18:00 UTC which seems to point at it losing timezone information:
> !Screen Shot 2019-05-13 at 2.41.54 PM.png!
>  
> I added some logging in the Airflow code around the default_args initialization and it confirmed the hypothesis that the default_args were being mutated:
>  
> {noformat}
> [2019-05-13 18:40:10,409] {__init__.py:3045} INFO - default_args for DAG tutorial_1: {'owner': 'airflow', 'start_date': datetime.datetime(2019, 5, 11, 0, 0)}
> [2019-05-13 18:40:10,410] {__init__.py:3045} INFO - default_args for DAG tutorial_2: {'owner': 'airflow', 'start_date': <Pendulum [2019-05-11T04:00:00+00:00]>}
> {noformat}
>  
>  
> As a simple fix, I changed the DAG definition to:
> {noformat}
> dag = DAG(f"tutorial_{dag_name}", default_args=default_args, schedule_interval=schedule_interval){noformat}
> and this seems to fix the problem:
>  
> {noformat}
> [2019-05-13 18:44:44,674] {__init__.py:3045} INFO - default_args for DAG tutorial_1: {'owner': 'airflow', 'start_date': datetime.datetime(2019, 5, 11, 0, 0)}
> [2019-05-13 18:44:44,676] {__init__.py:3045} INFO - default_args for DAG tutorial_2: {'owner': 'airflow', 'start_date': datetime.datetime(2019, 5, 11, 0, 0)}
> {noformat}
>  
> !Screen Shot 2019-05-13 at 6.45.25 PM.png!
> I want to add a fix to create a deep-copy of default_args here: [https://github.com/apache/airflow/blob/master/airflow/models/dag.py#L197]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)