Opened 28 hours ago

Last modified 23 hours ago

#36265 new New feature

Add support for serializing zoneinfo.ZoneInfo objects in migrations

Reported by: Sandeep Harlalka Owned by:
Component: Migrations Version: 5.1
Severity: Normal Keywords:
Cc: Sandeep Harlalka Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (2)

comment:1 by Sarah Boyce, 26 hours ago

Note for others trying to replicate:

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,
    )

comment:2 by Sarah Boyce, 23 hours ago

Summary: Generated Field with TruncDate and tzinfoAdd support for serializing zoneinfo.ZoneInfo objects in migrations
Triage Stage: UnreviewedAccepted
Type: BugNew feature

As zoneinfo.ZoneInfo objects are not supported in migrations (see docs: https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing), I have classed this as a new feature rather than a bug

Note: See TracTickets for help on using tickets.
Back to Top