[Django] #26183: Postgres backend: Time Field is created without time zone, cascading problems when changing this

50 views
Skip to first unread message

Django

unread,
Feb 8, 2016, 9:05:08 AM2/8/16
to django-...@googlegroups.com
#26183: Postgres backend: Time Field is created without time zone, cascading
problems when changing this
-------------------------------------+-------------------------------------
Reporter: schtibe | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: postgres, timezone,
Severity: Normal | time field
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
The documentation states that "The PostgreSQL backend stores datetimes as
timestamp with time zone."
Sadly, it does not do that with the TimeField, which can easily be seen in
db/backend/postgres_psycopg2/base.py line 97. In my opinion, it would be
nice to have the same behaviour for both the DateTimeField and the
TimeField.

It's easy to change this line to

{{{
'TimeField': 'time with time zone'
}}}

which does work. But there is a problem:
I wanted to do a pull request so I changed the line. Now I had problems
with my migrations file, since I have one that alters a field from
TimeField (which was now "with time zone") to a interval. Postgres does
not like that and throws

{{{
django.db.utils.ProgrammingError: column "duration" cannot be cast
automatically to type interval
HINT: You might need to specify "USING duration::interval".
}}}

So I did that and executed, by hand:

{{{
ALTER TABLE "resource_check_testtyperesourcetype" ALTER COLUMN
"duration" TYPE interval USING duration::interval;
}}}

Now it says: '''ERROR: cannot cast type time with time zone to interval
at character 103'''

So now I'm not sure if it is even a good idea to change the default
behaviour of TimeField to "with time zone"....

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

Django

unread,
Feb 8, 2016, 11:54:16 AM2/8/16
to django-...@googlegroups.com
#26183: PostgreSQL backend: TimeField is created without time zone

-------------------------------------+-------------------------------------
Reporter: schtibe | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: postgres, timezone, | Triage Stage:
time field | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => wontfix


Comment:

This is by design
[https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#naive-and-
aware-datetime-objects as documented]:

Python’s `datetime.time` objects also feature a `tzinfo` attribute, and
PostgreSQL has a matching `time with time zone type`. However, as
PostgreSQL’s docs put it, this type “exhibits properties which lead to
questionable usefulness”.
[[BR]]
Django only supports naive time objects and will raise an exception if
you attempt to save an aware time object, as a timezone for a time with no
associated date does not make sense.

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

Django

unread,
Feb 9, 2016, 4:58:22 AM2/9/16
to django-...@googlegroups.com
#26183: PostgreSQL backend: TimeField is created without time zone
-------------------------------------+-------------------------------------
Reporter: schtibe | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: postgres, timezone, | Triage Stage:
time field | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by schtibe):

Right, thank you for clarification.

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

Reply all
Reply to author
Forward
0 new messages