On the latest version, "django-timezone-field==7.1", and PostgreSQL
I ran into some unexpected behavior with the __isnull lookup when using null=True on a TimeZoneField. I wanted to check if this is intended behaviour or a bug.
When I filter for non-null timezone values using time_zone__isnull=False, I still get records where time_zone is None:
from django.db import models
from timezone_field import TimeZoneField
class MyModel(models.Model):
time_zone = TimeZoneField(null=True, blank=True)
# Create a record with None timezone
obj = MyModel.objects.create(time_zone=None)
results = MyModel.objects.filter(time_zone__isnull=False) # <- This should exclude the record above, but it doesn't
Looking at the code, _get_python_and_db_repr always returns an empty string for the database representation when the value is None, regardless of the null setting:
def _get_python_and_db_repr(self, value):
if value is None or value == "":
return (None, "")
Is the current behaviour intentional? There is a workaround using .exclude(time_zone="").
On the latest version,
"django-timezone-field==7.1", and PostgreSQLI ran into some unexpected behavior with the
__isnulllookup when usingnull=Trueon aTimeZoneField. I wanted to check if this is intended behaviour or a bug.When I filter for non-null timezone values using
time_zone__isnull=False, I still get records wheretime_zoneisNone:Looking at the code,
_get_python_and_db_repralways returns an empty string for the database representation when the value isNone, regardless of the null setting:Is the current behaviour intentional? There is a workaround using
.exclude(time_zone="").