-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
fix(TimeSensorAsync): use DAG timezone #33406
Conversation
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)
|
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f1b7164
to
9e4188b
Compare
111b32f
to
df03cf2
Compare
df03cf2
to
c8280bd
Compare
c8280bd
to
1038de7
Compare
tests/sensors/test_time_sensor.py
Outdated
): | ||
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert hasattr(op.target_datetime.tzinfo, "offset") |
If this does not have a timezone the next line would just straight fail anyway
There was a problem hiding this comment.
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.
tests/sensors/test_time_sensor.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1038de7
to
50a51a0
Compare
): | ||
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
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.