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: Fix non-UTC timestamps #3461

Merged
merged 2 commits into from
Aug 27, 2024
Merged

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Aug 26, 2024

Fixes a bug where all datetime timestamps in an event payload were serialized as if they were UTC timestamps, even if they were non-UTC timestamps, completely ignoring the timezone. Now, we convert all datetime objects to UTC before formatting them as a UTC timestamp.

Fixes #3453.

Copy link

codecov bot commented Aug 26, 2024

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
11521 4 11517 1636
View the top 3 failed tests by shortest run time
tests.integrations.aws_lambda.test_aws test_init_error[python3.9]
Stack Traces | 15.8s run time
.../integrations/aws_lambda/test_aws.py:334: in test_init_error
    (event,) = envelope_items
E   ValueError: not enough values to unpack (expected 1, got 0)
tests.integrations.aws_lambda.test_aws test_init_error[python3.10]
Stack Traces | 15.8s run time
.../integrations/aws_lambda/test_aws.py:334: in test_init_error
    (event,) = envelope_items
E   ValueError: not enough values to unpack (expected 1, got 0)
tests.integrations.aws_lambda.test_aws test_init_error[python3.11]
Stack Traces | 15.9s run time
.../integrations/aws_lambda/test_aws.py:334: in test_init_error
    (event,) = envelope_items
E   ValueError: not enough values to unpack (expected 1, got 0)

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@szokeasaurusrex
Copy link
Member Author

Looks like this maybe does not work on Python <3.12

@szokeasaurusrex
Copy link
Member Author

Yeah, seems that %:z was introduced in 3.12, since it is not mentioned in the 3.11 docs

@szokeasaurusrex szokeasaurusrex marked this pull request as draft August 27, 2024 06:57
sentry_sdk/utils.py Outdated Show resolved Hide resolved
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-timestamps branch 2 times, most recently from a456a68 to d7669f9 Compare August 27, 2024 09:28
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review August 27, 2024 09:29
tests/test_utils.py Outdated Show resolved Hide resolved
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-timestamps branch from d7669f9 to efc8e56 Compare August 27, 2024 09:43
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-timestamps branch from efc8e56 to 79e04c4 Compare August 27, 2024 10:55
Fixes a bug where all `datetime` timestamps in an event payload were serialized as if they were UTC timestamps, even if they were non-UTC timestamps, completely ignoring the timezone. Now, we convert all datetime objects to UTC before formatting them as a UTC timestamp.

Fixes #3453
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-timestamps branch from 79e04c4 to 99be567 Compare August 27, 2024 10:55
@szokeasaurusrex szokeasaurusrex enabled auto-merge (squash) August 27, 2024 11:01
@szokeasaurusrex szokeasaurusrex merged commit bde87ff into master Aug 27, 2024
122 of 123 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/fix-timestamps branch August 27, 2024 14:48
arjennienhuis pushed a commit to arjennienhuis/sentry-python that referenced this pull request Sep 30, 2024
Fixes a bug where all `datetime` timestamps in an event payload were serialized as if they were UTC timestamps, even if they were non-UTC timestamps, completely ignoring the timezone. Now, we convert all datetime objects to UTC before formatting them as a UTC timestamp.

Fixes getsentry#3453
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.

Fix datetime serialization for non-UTC timestamps
3 participants