Opened 3 weeks ago

Last modified 3 weeks ago

#37104 assigned Cleanup/optimization

Naive timestamps used in migrations should reference the same timezone

Reported by: James Beith Owned by: Vishy
Component: Migrations Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When creating a migration there are two reference timestamps; one in the filename (e.g. 0002_auto_20260518_0601.py) and one in the source header (e.g. # Generated by Django 6.0.5 on 2026-05-18 05:01).

The filename is created here, using current local date and time (from Python's runtime perspective), in this example "Europe/London".

The source header is created here, using UTC if settings.USE_TZ, otherwise current local date and time similar to filename.

This can lead to different (naive) timestamps used in the filename and source header. Is there any reason why they shouldn't be the same?

In terms of a fix, I think the change might be to have the filename call the Django timezone util instead of straight to Python's now classmethod.

Change History (3)

comment:1 by Sarah Boyce, 3 weeks ago

Component: Database layer (models, ORM)Migrations
Triage Stage: UnreviewedAccepted

Thank you for the report

comment:2 by Vishy, 3 weeks ago

Owner: set to Vishy
Status: newassigned

comment:3 by Vishy, 3 weeks ago

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