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

test: Fix UTC assuming test #3722

Merged
merged 1 commit into from
Oct 31, 2024
Merged

test: Fix UTC assuming test #3722

merged 1 commit into from
Oct 31, 2024

Conversation

BYK
Copy link
Member

@BYK BYK commented Oct 31, 2024

Fixes #3720.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.28%. Comparing base (ce9986c) to head (b79350a).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3722   +/-   ##
=======================================
  Coverage   84.28%   84.28%           
=======================================
  Files         133      133           
  Lines       14261    14261           
  Branches     2405     2405           
=======================================
  Hits        12020    12020           
  Misses       1490     1490           
  Partials      751      751           

see 2 files with indirect coverage changes

@BYK BYK enabled auto-merge (squash) October 31, 2024 15:19
@BYK BYK requested a review from asottile-sentry October 31, 2024 15:19
Comment on lines 70 to +73
(
"2021-01-01T00:00:00.000000",
datetime(2021, 1, 1, tzinfo=timezone.utc),
), # No TZ -- assume UTC
datetime(2021, 1, 1).astimezone(timezone.utc),
), # No TZ -- assume local but convert to UTC
Copy link
Member

Choose a reason for hiding this comment

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

given the comment I actually think the implementation is incorrect and should be something like:

try:
   dt = datetime.fromisoformat(s)
except ...:
    ...
else:
   if dt.tzinfo is None:
       return dt.replace(tzinfo=UTC)
   else:
       return dt.astimezone(UTC)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote that comment 😅 And after reading the ISO 8601 spec, I think I was mistaken:

https://en.wikipedia.org/wiki/ISO_8601#Local_time_(unqualified)

If no UTC relation information is given with a time representation, the time is assumed to be in local time.

Now there's the obvious warning this being unsafe in the next sentence but I'm split between being spec-compliant or "doing the right thing" which may confuse people if they rely on the spec.

What's your take @asottile-sentry?

Copy link
Member

Choose a reason for hiding this comment

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

I suspect it won't matter as most should run their servers in UTC anyway -- so I guess we can go with the current implementation

it seems to only be used to sort breadcrumbs in the event payload (is that even necessary? surely relay or the frontend should sort those right? do we even need this function and the caller?)

Copy link
Member Author

Choose a reason for hiding this comment

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

surely relay or the frontend should sort those right?

Agree with this but maybe we're trying to save resources? It also seems like the side effect of converting a string to a python date might be something we are after here. That said that python date will then be converted back into an ISO 8601 timestamp so 🤷🏻

Will ask ingest folks.

Copy link
Member

@asottile-sentry asottile-sentry left a comment

Choose a reason for hiding this comment

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

maybe we can just delete this code?

@BYK BYK merged commit 5c5d98a into master Oct 31, 2024
136 checks passed
@BYK BYK deleted the byk/test/fix-utc-issue branch October 31, 2024 15:59
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.

Test assumes system timezone is UTC
2 participants