Skip to content

BranchDateTimeOperator Does Not Work According to DAG Timezone #40151

Closed as not planned

Description

@SeunghoJung

Apache Airflow version

Other Airflow 2 version (please specify below)

If "Other Airflow 2 version" selected, which one?

2.8.1

What happened?

When executing a DAG in KST (a specific timezone, NOT UTC), lower and upper bounds do not function correctly when set as follows:

  1. Set lower to 07:00 and upper to 23:00, assuming the task finishes at 07:50 KST.
  2. The task's finish time is set to 22:50 UTC of the previous day, and both lower and upper are set to the same day, which is in the DAG timezone of KST.
  3. As a result, follow_task_ids_if_true is not followed, leading to unintended outcomes.
  4. When printing each time, the output is as follows:
AS-IS
now: 2024-06-08 22:50:00+00:00, lower: 2024-06-08 07:00:00+09:00, upper: 2024-06-08 23:00:00+09:00
# result: follow_task_ids_if_false

TO-BE
now: 2024-06-09 07:50:00+00:00, lower: 2024-06-09 07:00:00+09:00, upper: 2024-06-09 23:00:00+09:00
# result: follow_task_ids_if_true

I believe that this issue can be resolved if the 'now' and 'logical_date' calculation follows the DAG's timezone.

Thank you for looking into this issue.

What you think should happen instead?

No response

How to reproduce

  1. Create a wrapper for BranchDateTimeOperator and import this function.
  2. Create a DAG as suggested in the Airflow example and set the timezone of the DAG's start_date to Asia/Seoul.
  3. Set lower to 07:00 and upper to 23:00.
  4. Modify the now value in choose_branch method of the wrapper class as shown below:
    now = timezone.coerce_datetime(timezone.utcnow())
    # KST 07:50, Set the date to the previous day based on the execution day in KST.  
    timezone.coerce_datetime(datetime.datetime(2024, 6, 8, 22, 50, 00, tzinfo=pendulum.timezone("UTC"))) 
  5. Print now, lower, and upper inside the wrapper for debugging.
  6. Execute your DAG.
  7. The result will be follow_task_ids_if_false, which is not as intended.

Operating System

MWAA on AWS

Versions of Apache Airflow Providers

No response

Deployment

Amazon (AWS) MWAA

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Jun 9, 2024
  2. boring-cyborg commented on Jun 9, 2024

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. idantepper commented on Jun 9, 2024

    @idantepper
    Contributor

    Hi I would like to take this issue

  4. added
    _eol_affected_version:2.9
    _eol_affected_version:2.8
    and removed
    needs-triage
    _eol_affected_version:2.9
    on Jun 9, 2024
  5. SeunghoJung commented on Jun 12, 2024

    @SeunghoJung
    Author

    @idantepper How is going on this issue?

  6. prasad-madine commented on Feb 5, 2025

    @prasad-madine

    Hello @SeunghoJung , Is this issue still exists?

  7. prasad-madine commented on Feb 10, 2025

    @prasad-madine

    Hello @SeunghoJung ,

    In the first image, I have modified the now(current) datetime as 2025, 2, 6, 22, 50, 00 and given the lower and upper bounds as 2025, 2, 7, 7, 0 and 2025, 2, 7, 23, 0 and getting the output correctly which is date_in_range(which is assigned to follow_task_ids_if_true). You can see the output in third image and this issue doesn't lies in this version 3.0.0.

    Image

    Image

    Image

    Thankyou.

  8. github-actions commented on Mar 24, 2025

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.

  9. added
    stale
    on Mar 24, 2025
  10. github-actions commented on Apr 1, 2025

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    _eol_affected_version:2.8area:providersgood first issuekind:bugpending-responseprovider:standardstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions