Skip to content

test(django): make DRF DST regression exercise TIME_ZONE - #21436

Draft
vlad-scherbich wants to merge 1 commit into
mainfrom
vlad/fix-drf-ambiguous-time-416
Draft

vlad-scherbich wants to merge 1 commit into
mainfrom
vlad/fix-drf-ambiguous-time-416

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

William Conti asked for this test fix: "looks good tho should fix the test", and on the review note that the old check never looked at TIME_ZONE.

The version he reviewed formatted a fixed datetime(2026, 11, 1, 1, 51, 26, 582942) and only checked that the string was non-empty. test_dst_fall_back_ambiguous_local_time_formats still uses that timestamp. It asserts settings.TIME_ZONE == "UTC", asserts date_format(..., "r") is non-empty, and on Django before 4.0 asserts timezone.make_aware raises AmbiguousTimeError for that timestamp with TIME_ZONE set to America/Chicago.

Testing

  • green CI

@vlad-scherbich vlad-scherbich added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 2, 2026
@vlad-scherbich
vlad-scherbich marked this pull request as ready for review November 2, 2026 02:49
@vlad-scherbich
vlad-scherbich requested review from a team as code owners November 2, 2026 02:49
@vlad-scherbich
vlad-scherbich requested review from wantsui and removed request for a team November 2, 2026 02:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T12:09:48.613150Z 192833e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

tests/contrib/djangorestframework/test_djangorestframework.py           @DataDog/python-guild @DataDog/apm-idm-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 102 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 102 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=122)
ddtrace.llmobs._integrations.litellm -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._utils -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._integrations.crewai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._telemetry -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

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.

Bits Code Review: PASS

More details

Setting the DRF test app to UTC removes the DST ambiguity in date formatting. The added regression test exercises a timestamp from the repeated fall-back hour.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2f94deb

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues remain for the test-only change addressing daylight-saving timestamp ambiguity.

No open issues 🎉

What changed in this PR

This test-only change stabilizes the Django REST Framework integration suite by avoiding daylight-saving fall-back ambiguity in Django’s date formatting.

Changes:

  • Set the test app’s time zone to UTC to prevent pytz.AmbiguousTimeError.
  • Add a regression test that formats a timestamp from the US fall-back hour.
File Description
tests/​contrib/​djangorestframework/​test_djangorestframework.py Adds a regression test for fall-back timestamp formatting.
tests/​contrib/​djangorestframework/​app/​settings.py Sets TIME_ZONE = "UTC" and explains the DST safeguard.

Review effort: Balanced

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

/code blockers

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e987294359

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-02 15:34:33 UTC ℹ️ Start processing command /code blockers


2026-11-02 15:34:35 UTC

Detected 3 merge blocker(s) to address:

🔴 Blocking

  • Requires at least 1 approval, only has 0.
    Hint: Get an approval from any reviewer.

🟠 Pending

wconti27

This comment was marked as resolved.

The naive date_format check on #21436 stayed green under zoneinfo even
without UTC. Pin TIME_ZONE=UTC and exercise |date "r" / make_aware so
Chicago still fails on pytz Django in this suite.
@vlad-scherbich
vlad-scherbich force-pushed the vlad/fix-drf-ambiguous-time-416 branch from e987294 to 192833e Compare November 3, 2026 12:04
@vlad-scherbich
vlad-scherbich requested review from a team as code owners November 3, 2026 12:04
@vlad-scherbich
vlad-scherbich requested review from emmettbutler, florentinl, gyuheon0h and sabrenner and removed request for a team November 3, 2026 12:04
@vlad-scherbich vlad-scherbich changed the title test(django): use UTC in DRF app to avoid DST AmbiguousTimeError test(django): make DRF DST regression exercise TIME_ZONE Nov 3, 2026
@vlad-scherbich
vlad-scherbich changed the base branch from 4.16 to main November 3, 2026 12:04

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

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.

Bits Code Review: PASS

More details

The explicit UTC assertion catches configuration regressions even on zoneinfo-backed Django, where ambiguous local times do not raise. The completed static review identified no reportable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 192833e

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

looks good tho should fix the test

@wconti27 Done, please take a look at the new test.

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

DDCI - DataDog/dd-trace-py | download win_arm64 wheels

View more details · View in DDCI

DataDog/apm-reliability/dd-trace-py | download win_arm64 wheels

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 192833e | Docs | View more details | Give us feedback!

Comment on lines +21 to +43
@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()

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 ?

@vlad-scherbich
vlad-scherbich marked this pull request as draft November 3, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants