SeunghoJung opened a new issue, #40151:
URL: https://github.com/apache/airflow/issues/40151

   ### 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:
   ```bash
   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-08 07:00:00+09:00, upper: 
2024-06-08 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](https://airflow.apache.org/docs/apache-airflow/2.4.0/howto/operator/datetime.html#usage-with-current-time)
 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:
       
https://github.com/apache/airflow/blob/fc4fbb3dcf1f2c241ed65b564214aaf853d14a9a/airflow/operators/datetime.py#L85
       ```python
       # 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?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to