Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/contrib/djangorestframework/test_djangorestframework.py
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
Expand All @@ -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")
Comment thread
vlad-scherbich marked this conversation as resolved.
Resolved
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
Loading