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

Use localize instead of replace when writing tz info #1026

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

KaspariK
Copy link
Member

@KaspariK KaspariK commented Jan 17, 2025

We recently encountered an issue where the run_time for JobRun instances was consistently offset by 7 minutes earlier than the expected time. This was causing scheduled Jobs to execute earlier than intended, leading to incorrect Job executions.

This issue looks to related to our use of run_time.replace(tzinfo=...) which incorrectly handles timezone writing. This misuse resulted in the run_time being assigned a tzinfo with an unexpected offset, such as <DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>, which has an offset of -7 minutes from the expected timezone offset.

Note: I do think adding tests would be ideal, but I haven't gotten that far.

@KaspariK KaspariK marked this pull request as ready for review January 17, 2025 17:53
@KaspariK KaspariK requested a review from a team as a code owner January 17, 2025 17:53
nemacysts
nemacysts previously approved these changes Jan 17, 2025
Comment on lines 117 to 119
run_time_str = json_data["run_time"]
if run_time_str:
run_time = datetime.datetime.fromisoformat(run_time_str)
Copy link
Member

Choose a reason for hiding this comment

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

i'm personally not a fan of adding a suffix to variables with their type and would propose something like

Suggested change
run_time_str = json_data["run_time"]
if run_time_str:
run_time = datetime.datetime.fromisoformat(run_time_str)
raw_run_time = json_data["run_time"]
if raw_run_time:
run_time = datetime.datetime.fromisoformat(raw_run_time)

but i won't block on this :)

@KaspariK KaspariK merged commit 4145c0e into master Jan 17, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants