#32661: An exception should be raised when trying to save an aware time object.
-------------------------------------+-------------------------------------
Reporter: Armin Stepanjan | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone, datetime, | Triage Stage: Accepted
datetimefield, timefield, models |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* cc: Aymeric Augustin (added)
* easy: 1 => 0
* stage: Unreviewed => Accepted
Comment:
> This issue suggests two changes, happy to make a PR if the community
aggrees with them:
>
> 1. Mention that TimeField drops timezone in Model field reference:
https://docs.djangoproject.com/en/3.2/ref/models/fields/#timefield
It's already [https://docs.djangoproject.com/en/dev/topics/i18n/timezones
/#naive-and-aware-datetime-objects documented] that: ''"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."''
> 2. Throw a warning when a TimeField with tzinfo is saved (similarly as
there's a warning when a naive DateTimeField is saved).
Django should raise an exception if you attempt to save an aware time
object (at least on
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/backends/oracle/operations.py#L552-L553
Oracle],
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/backends/mysql/operations.py#L262-L263
MySQL], and
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/backends/sqlite3/operations.py#L272-L273
SQLite]), however it looks that `timezone.is_aware()` doesn't work for
`datetime.time`.
{{{
>>> t = datetime.time(21, 22, 23, 240000,
tzinfo=timezone.get_current_timezone())
>>> t.tzinfo
<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD>
>>> timezone.is_aware(t)
False
}}}
Maybe it's enough to check `tzinfo`.
--
Ticket URL: <https://code.djangoproject.com/ticket/32661#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.620fb75d136891787a48c666b0f9994a%40djangoproject.com.