Opened 6 months ago

Closed 5 months ago

#36265 closed New feature (fixed)

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: Ready for checkin
Has patch: yes 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.

Change History (11)

comment:1 by Sarah Boyce, 6 months 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, 6 months 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

comment:3 by 송준호, 5 months ago

Owner: set to 송준호
Status: newassigned

comment:4 by 송준호, 5 months ago

Has patch: set
Triage Stage: AcceptedUnreviewed

comment:5 by 송준호, 5 months ago

Has patch: unset
Triage Stage: UnreviewedAccepted

comment:6 by 송준호, 5 months ago

Has patch: set
Triage Stage: AcceptedUnreviewed

comment:7 by JaeHyuckSa, 5 months ago

Triage Stage: UnreviewedAccepted

comment:8 by Sarah Boyce, 5 months ago

Needs documentation: set

comment:9 by JaeHyuckSa, 5 months ago

Needs documentation: unset

comment:10 by Sarah Boyce, 5 months ago

Triage Stage: AcceptedReady for checkin

comment:11 by Sarah Boyce <42296566+sarahboyce@…>, 5 months ago

Resolution: fixed
Status: assignedclosed

In 126417be:

Fixed #36265 -- Added support for serialization of ZoneInfo instances in migrations.

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