Repository navigation
test(django): make DRF DST regression exercise TIME_ZONE #21436
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
Draft
vlad-scherbich
wants to merge
1
commit into
main
Choose a base branch
from
vlad/fix-drf-ambiguous-time-416
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| from datetime import datetime | ||
| import os | ||
|
|
||
| import django | ||
| from django.conf import settings | ||
| from django.test.utils import override_settings | ||
| from django.utils import timezone | ||
| from django.utils.dateformat import format as date_format | ||
| from django.utils.timezone import get_default_timezone | ||
| import pytest | ||
|
|
||
| from ddtrace.constants import _SAMPLING_PRIORITY_KEY | ||
|
|
@@ -12,6 +18,30 @@ | |
| from tests.utils import override_global_config | ||
|
|
||
|
|
||
| @pytest.mark.skipif(django.VERSION < (1, 10), reason="requires django version >= 1.10") | ||
| def test_dst_fall_back_ambiguous_local_time_formats() -> None: | ||
| # Django's 500 log-email templates format "now" with |date "r". With USE_TZ off, | ||
| # that is a naive wall-clock stamp make_aware'd in TIME_ZONE. Under pytz, | ||
| # America/Chicago raises AmbiguousTimeError for 01:xx on US fall-back night; | ||
| # UTC has no DST, so the same stamp formats cleanly. zoneinfo (Django 4+) does | ||
| # not raise on ambiguous times, so we also pin TIME_ZONE=UTC explicitly. | ||
| ambiguous_local: datetime = datetime(2026, 11, 1, 1, 51, 26, 582942) | ||
|
|
||
| assert settings.TIME_ZONE == "UTC" | ||
| formatted: str = date_format(ambiguous_local, "r") | ||
| assert formatted | ||
|
|
||
| # Confirm Chicago still blows up on pytz Django (2.2/3.2 in this suite). Without | ||
| # this, removing TIME_ZONE=UTC would leave Django 4 rows green forever. | ||
| if django.VERSION < (4, 0): | ||
| with override_settings(TIME_ZONE="America/Chicago"): | ||
| get_default_timezone.cache_clear() | ||
| with pytest.raises(Exception) as exc_info: | ||
| timezone.make_aware(ambiguous_local, get_default_timezone()) | ||
| assert type(exc_info.value).__name__ == "AmbiguousTimeError" | ||
| get_default_timezone.cache_clear() | ||
|
|
||
|
Comment on lines
+21
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do all of that for something that will happen once a year ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like what are we really testing there ? |
||
|
|
||
| @pytest.mark.skipif(django.VERSION < (1, 10), reason="requires django version >= 1.10") | ||
| @pytest.mark.django_db | ||
| def test_trace_exceptions(client, test_spans): # noqa flake8 complains about shadowing test_spans | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.