Skip to content

Fix graphite.util.epoch for Django 5#2914

Open
samestep wants to merge 1 commit into
graphite-project:masterfrom
samestep:fix-epoch-naive-django5
Open

Fix graphite.util.epoch for Django 5#2914
samestep wants to merge 1 commit into
graphite-project:masterfrom
samestep:fix-epoch-naive-django5

Conversation

@samestep

@samestep samestep commented Jun 3, 2026

Copy link
Copy Markdown

This PR fixes the test_epoch_naive failure that currently occurs when running the Graphite test suite with Django 5; as a specific reproducible example, here's the relevant nix-build -A python3Packages.graphite-web log snippet at NixOS/nixpkgs@4060765:

FAIL: test_epoch_naive (tests.test_util.UtilTest.test_epoch_naive)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/nix/store/ccf31a4yhdqra20xb8yjcps9rlp42q5h-python3.13-mock-5.2.0/lib/python3.13/site-packages/mock/mock.py", line 1468, in patched
    return func(*newargs, **newkeywargs)
  File "/build/source/webapp/tests/test_util.py", line 40, in test_epoch_naive
    self.assertEqual(util.epoch(dt), 600)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
AssertionError: 1020 != 600

#2886 added support for Django 5, but this repo's CI didn't catch the test failure because the tox configuration forces Django 4:

- name: Test with tox
env:
TEST_REDIS_HOST: localhost
TEST_REDIS_PORT: ${{ job.services.redis.ports[6379] }}
TEST_MYSQL_HOST: localhost
TEST_MYSQL_PORT: ${{ job.services.mariadb.ports[3306] }}
TEST_MYSQL_PASSWORD: graphite
TEST_POSTGRES_HOST: localhost
TEST_POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
TEST_POSTGRESQL_PASSWORD: graphite
run: |
tox

Django>=4.2,<5

The reason the test fails is because of a change in Django 5:

Support for pytz timezones is removed.

Specifically, django/django@e6f8243 removed the pytz-specific branch from django.utils.timezone.make_aware.

The fix is to replace this make_aware call with code equivalent to what the Django 4 implementation of make_aware would have done. Note that the effect of is_dst=None is to raise in some specific cases; otherwise the localize method defaults to is_dst=False, which would silently use standard time in those cases.

The other make_aware call (in the epoch_to_dt function) does not need to change because the UTC timezone is unaffected by this Django behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.90%. Comparing base (5df4cd4) to head (a2fdc90).
⚠️ Report is 13 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2914      +/-   ##
==========================================
+ Coverage   76.80%   76.90%   +0.09%     
==========================================
  Files          88       88              
  Lines        9700     9703       +3     
  Branches     1805     1806       +1     
==========================================
+ Hits         7450     7462      +12     
+ Misses       1983     1971      -12     
- Partials      267      270       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants