[Django] #34680: inspectdb on mysql timestamp fields leads to timezone issues

7 views
Skip to first unread message

Django

unread,
Jun 26, 2023, 10:09:31 PM6/26/23
to django-...@googlegroups.com
#34680: inspectdb on mysql timestamp fields leads to timezone issues
-------------------------------------+-------------------------------------
Reporter: neilbags | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 4.2
layer (models, ORM) | Keywords: inspectdb, mysql,
Severity: Normal | timestamp
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using inspectdb on a MySQL database timestamp columns in MySQL are
generated as DateTime fields in Django models. On the surface this appears
to work, however, MySQL makes timezone adjustments for timestamps and not
for datetimes.

Since Django expects these columns to be datetime, if the server timezone
is changed, incorrect dates/times are returned. I saw this in the wild
with
some created_at and updated_at columns that were created as timestamp
fields by Laravel.

I'm not sure if this is something that should be fixed. Maybe the
inspectdb feature could give a warning when encountering these columns, or
this could be documented as a caveat in the section on inspectdb and/or
the howto on dealing with legacy databases.

--
Ticket URL: <https://code.djangoproject.com/ticket/34680>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 26, 2023, 10:11:46 PM6/26/23
to django-...@googlegroups.com
#34680: inspectdb on mysql timestamp fields leads to timezone issues
-------------------------------------+-------------------------------------
Reporter: neilbags | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: inspectdb, mysql, | Triage Stage:
timestamp | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by neilbags:

Old description:

> When using inspectdb on a MySQL database timestamp columns in MySQL are
> generated as DateTime fields in Django models. On the surface this
> appears to work, however, MySQL makes timezone adjustments for timestamps
> and not for datetimes.
>
> Since Django expects these columns to be datetime, if the server timezone
> is changed, incorrect dates/times are returned. I saw this in the wild
> with
> some created_at and updated_at columns that were created as timestamp
> fields by Laravel.
>
> I'm not sure if this is something that should be fixed. Maybe the
> inspectdb feature could give a warning when encountering these columns,
> or this could be documented as a caveat in the section on inspectdb
> and/or the howto on dealing with legacy databases.

New description:

When using inspectdb on a MySQL database timestamp columns are generated


as DateTime fields in Django models. On the surface this appears to work,
however, MySQL makes timezone adjustments for timestamps and not for
datetimes.

Since Django expects these columns to be datetime, if the server timezone
is changed, incorrect dates/times are returned. I saw this in the wild
with
some created_at and updated_at columns that were created as timestamp
fields by Laravel.

I'm not sure if this is something that should be fixed. Maybe the
inspectdb feature could give a warning when encountering these columns, or
this could be documented as a caveat in the section on inspectdb and/or
the howto on dealing with legacy databases.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34680#comment:1>

Django

unread,
Jun 26, 2023, 11:26:13 PM6/26/23
to django-...@googlegroups.com
#34680: inspectdb on mysql timestamp fields leads to timezone issues
-------------------------------------+-------------------------------------
Reporter: neilbags | Owner: nobody
Type: Uncategorized | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: inspectdb, mysql, | Triage Stage:
timestamp | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #19312. This caveat is already
[https://docs.djangoproject.com/en/stable/ref/databases/#timestamp-columns
documented].

--
Ticket URL: <https://code.djangoproject.com/ticket/34680#comment:2>

Reply all
Reply to author
Forward
0 new messages