Skip to content

Commit f38dcdd

Browse files
authored
Fixed RemovedInDjango50Warning in handle_timezone with Django 4.2. (#1581)
Fixes #1580. Unless USE_DEPRECATED_PYTZ is present and True, we should not be passing the is_dst parameter.
1 parent b84d0ec commit f38dcdd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

django_filters/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,18 @@ def resolve_field(model_field, lookup_expr):
231231

232232
def handle_timezone(value, is_dst=None):
233233
if settings.USE_TZ and timezone.is_naive(value):
234-
if django.VERSION < (5, 0):
234+
# Pre-4.x versions of Django have is_dst. Later Django versions have
235+
# zoneinfo where the is_dst argument has no meaning. is_dst will be
236+
# removed in the 5.x series.
237+
#
238+
# On intermediate versions, the default is to use zoneinfo, but pytz
239+
# is still available under USE_DEPRECATED_PYTZ, and is_dst is
240+
# meaningful there. Under those versions we should only use is_dst
241+
# if USE_DEPRECATED_PYTZ is present and True; otherwise, we will cause
242+
# deprecation warnings, and we should not. See #1580.
243+
#
244+
# This can be removed once 3.2 is no longer supported upstream.
245+
if django.VERSION < (4, 0) or (django.VERSION < (5, 0) and settings.USE_DEPRECATED_PYTZ):
235246
return timezone.make_aware(value, timezone.get_current_timezone(), is_dst)
236247
return timezone.make_aware(value, timezone.get_current_timezone())
237248
elif not settings.USE_TZ and timezone.is_aware(value):

0 commit comments

Comments
 (0)