[Django] #36265: Generated Field with TruncDate and tzinfo

5 views
Skip to first unread message

Django

unread,
Mar 19, 2025, 4:01:11 AM3/19/25
to django-...@googlegroups.com
#36265: Generated Field with TruncDate and tzinfo
---------------------------------+--------------------------------------
Reporter: sandeepharlalka | Type: Bug
Status: new | Component: Migrations
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
in settings.py

{{{
USE_TZ = True
}}}


In models.py

{{{
class MyClass:
timestamp = models.DateTimeField()
date = models.GeneratedField(
expression=TruncDate('timestamp', tzinfo=INDIA_TIMEZONE),
output_field=models.DateField(),
db_persist=True,
)

}}}

makemigrations:
ValueError: Cannot serialize: zoneinfo.ZoneInfo(key='Asia/Kolkata')

date field is added after the table has already been created.
--
Ticket URL: <https://code.djangoproject.com/ticket/36265>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 19, 2025, 5:30:00 AM3/19/25
to django-...@googlegroups.com
#36265: Generated Field with TruncDate and tzinfo
----------------------------------+--------------------------------------
Reporter: Sandeep Harlalka | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by Sarah Boyce):

Note for others trying to replicate:
{{{#!python
from zoneinfo import ZoneInfo

from django.db import models
from django.db.models.functions import TruncDate


INDIA_TIMEZONE = ZoneInfo('Asia/Kolkata')

class MyModel(models.Model):
timestamp = models.DateTimeField()
date = models.GeneratedField(
expression=TruncDate('timestamp', tzinfo=INDIA_TIMEZONE),
output_field=models.DateField(),
db_persist=True,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36265#comment:1>
Reply all
Reply to author
Forward
0 new messages