carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections
https://django-filter.readthedocs.io/en/main/
Other
4.41k stars 767 forks source link

IsoDateTimeFromToRangeFilterTests fail with DST #1050

Open bmwiedemann opened 5 years ago

bmwiedemann commented 5 years ago

One test starts to fail 2019-03-10 08:00 UTC This coincides with a US DST 2019-03-10 02:00 (-0600) test works again after end of DST ~ 2019-11-04

======================================================================
FAIL: test_filtering (tests.test_filtering.IsoDateTimeFromToRangeFilterTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/abuild/rpmbuild/BUILD/django-filter-2.1.0/tests/test_filtering.py", line 1005, in test_filtering
    self.assertEqual(len(results.qs), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 487 tests in 0.981s

FAILED (failures=1, skipped=14, expected failures=3)

This bug was found while working on reproducible builds for openSUSE.

carltongibson commented 5 years ago

So is this a DST issue? Will it re-occur every year? (Can you propose a fix? 😉)

bmwiedemann commented 5 years ago

Yes, it is a DST issue and it re-occurs every year. I looked at the code, but since I'm not a python expert and relevant code is distributed across multiple files and classes, it was not easy to see where the problem comes from. Maybe pdb could show things...

carltongibson commented 5 years ago

OK, thanks for the report. I will have a play at some point.

carltongibson commented 5 years ago

OK, so this just showed up here: https://travis-ci.org/carltongibson/django-filter/builds/514228812 Happily take a PR. If not I'll look at it at DjangoCon Europe sprints.

lbazan commented 5 years ago

FAILED (skipped=14, expected failures=3, unexpected successes=1) Destroying test database for alias 'default'...

carltongibson commented 2 years ago

We'll need to revisit this after #1463.

Look into rewriting the test using @adamchainz's time-machine project

adamchainz commented 2 years ago

I think you could just decorate the test with:

@time_machine.travel(dt.datetime(2019, 3, 10, 7))

or similar, and the test will always run outside of DST.

carltongibson commented 2 years ago

That’s what I’m looking for. 😄