Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TimeSensorAsync): use DAG timezone #33406

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

SapphicCode
Copy link
Contributor

@SapphicCode SapphicCode commented Aug 15, 2023

Fixes: #33256

TimeSensorAsync used to convert naive times to UTC regardless of DAG timezone. This fixes that.

Please let me know if this is a significant change and I'll write a newsfragment file.

@boring-cyborg boring-cyborg bot added the area:core-operators Operators, Sensors and hooks within Core Airflow label Aug 15, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 15, 2023

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@SapphicCode SapphicCode marked this pull request as ready for review August 15, 2023 10:49
@@ -64,7 +64,7 @@ def __init__(self, *, target_time, **kwargs):
self.target_time = target_time

aware_time = timezone.coerce_datetime(
datetime.datetime.combine(datetime.datetime.today(), self.target_time)
datetime.datetime.combine(datetime.datetime.today(), self.target_time, self.dag.timezone)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@SapphicCode SapphicCode marked this pull request as draft September 4, 2023 08:19
@SapphicCode SapphicCode marked this pull request as ready for review September 5, 2023 06:27
@eladkal eladkal added the type:bug-fix Changelog: Bug Fixes label Sep 5, 2023
@eladkal eladkal added this to the Airflow 2.7.2 milestone Sep 5, 2023
):
op = TimeSensorAsync(task_id="test", target_time=pendulum.time(8, 0))
assert op.target_datetime.time() == pendulum.time(0, 0)
assert hasattr(op.target_datetime.tzinfo, "offset")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert hasattr(op.target_datetime.tzinfo, "offset")

If this does not have a timezone the next line would just straight fail anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied this from the previous test, but sure.

op = TimeSensorAsync(task_id="test", target_time=pendulum.time(8, 0))
assert op.target_datetime.time() == pendulum.time(0, 0)
assert hasattr(op.target_datetime.tzinfo, "offset")
assert op.target_datetime.tzinfo.offset == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should use a non-zero-offset timezone to make this more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it from 9 -> 1. I'm not sure if there's a :30 timezone that is not affected by DST like Singapore isn't.

):
op = TimeSensorAsync(task_id="test", target_time=pendulum.time(9, 0))
assert op.target_datetime.time() == pendulum.time(1, 0)
assert op.target_datetime.tzinfo == UTC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it fallbacks to UTC before this changes, should we test with another timezone instead?

Copy link
Contributor Author

@SapphicCode SapphicCode Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line you're referring to here, target_datetime, is the datetime being given to DateTimeTrigger -> defer. It must always be converted to UTC.
Code - 2023-09-20 08 40 43

@potiuk potiuk merged commit 6c50ef5 into apache:main Oct 12, 2023
42 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 12, 2023

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@SapphicCode SapphicCode deleted the cassandra/fix-timesensorasync branch October 16, 2023 11:27
ephraimbuddy pushed a commit that referenced this pull request Oct 29, 2023
* fix(TimeSensorAsync): use DAG timezone

Fixes: #33256
(cherry picked from commit 6c50ef5)
ephraimbuddy pushed a commit that referenced this pull request Oct 30, 2023
* fix(TimeSensorAsync): use DAG timezone

Fixes: #33256
(cherry picked from commit 6c50ef5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core-operators Operators, Sensors and hooks within Core Airflow type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TimeSensorAsync does not use DAG timezone to convert naive time input
7 participants