Fix graphite.util.epoch for Django 5 - #2914
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect epoch conversions for naive datetimes under Django 5 by avoiding django.utils.timezone.make_aware() for pytz time zones (where Django 5 no longer performs pytz-specific localize() handling). This restores Django 4–equivalent behavior and resolves the test_epoch_naive failure.
Changes:
- Replace
make_aware(dt, pytz.timezone(settings.TIME_ZONE))withpytz.timezone(...).localize(dt, is_dst=None)ingraphite.util.epoch()for naive datetimes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR fixes the
test_epoch_naivefailure that currently occurs when running the Graphite test suite with Django 5; as a specific reproducible example, here's the relevantnix-build -A python3Packages.graphite-weblog snippet at NixOS/nixpkgs@4060765:#2886 added support for Django 5, but this repo's CI didn't catch the test failure because the tox configuration forces Django 4:
graphite-web/.github/workflows/tests.yml
Lines 72 to 83 in b5d272b
graphite-web/tox.ini
Line 37 in b5d272b
The reason the test fails is because of a change in Django 5:
Specifically, django/django@e6f8243 removed the pytz-specific branch from
django.utils.timezone.make_aware.The fix is to replace this
make_awarecall with code equivalent to what the Django 4 implementation ofmake_awarewould have done. Note that the effect ofis_dst=Noneis toraisein some specific cases; otherwise thelocalizemethod defaults tois_dst=False, which would silently use standard time in those cases.The other
make_awarecall (in theepoch_to_dtfunction) does not need to change because the UTC timezone is unaffected by this Django behavior change.