mfogel / django-timezone-field

A Django app providing DB, form, and REST framework fields for zoneinfo and pytz timezone objects.
BSD 2-Clause "Simplified" License
397 stars 95 forks source link

use_pytz=True doesn't seem to be default on django 3.2.21 #111

Closed gilpinheiro closed 1 year ago

gilpinheiro commented 1 year ago

Approximating the code for simplicity. Python 3.9.5 running in production

class V(models.Model):
      timezone = TimeZoneField(
        choices=[(tz, tz) for tz in pytz.all_timezones], default="America/Toronto"
    )
>>> v = V.objects.get(id=1)
>>> v.timezone
zoneinfo.ZoneInfo(key='America/Toronto')

v.timezone is a ZoneInfo object

And with explicit default set:

class V(models.Model):
      timezone = TimeZoneField(
        choices=[(tz, tz) for tz in pytz.all_timezones], default="America/Toronto", use_pytz=True
    )
>>> v = V.objects.get(id=1)
>>> v.timezone
<DstTzInfo 'America/Toronto' LMT-1 day, 18:42:00 STD>

which is indeed a pytz object.

contradicting the documented default, (Django <= 3.X: use_pytz defaults to True)

I haven't had a chance to dig deeper, but I thought I'd report early.

mfogel commented 1 year ago

Thank for the bug report. I think this is a duplicate of #109, which should be fixed in the release I just pushed to pypi - v6.0.1. Please give it a try and re-open this if it doesn't work for you.