[Django] #27475: Bug in admin with date_hierarchy and Daylight savings

13 views
Skip to first unread message

Django

unread,
Nov 10, 2016, 5:56:52 PM11/10/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-----------------------------------------+------------------------
Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When I have a date_hierarchy in admin and I select a range with a record
with the day equal the day of a daylight savings I got an error of
NonExistentTimeError.

I discovered that indeed 2016-10-16 00:00:00 does not exist in my Timezone
('America/Sao_Paulo') because that was when Daylight Savings started.

So when I have a record with that date in my database, it will brake the
date_hierarchy feature.

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

Django

unread,
Nov 12, 2016, 10:09:46 AM11/12/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+--------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Tim Graham):

I'm not sure what the expected behavior is. What could Django do if you
have bad data?

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

Django

unread,
Nov 12, 2016, 10:39:19 AM11/12/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+--------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Hugo Tácito):

Hello Tim,

I'm sorry for my lack of information and clarity, but even if I do have an
existing datetime the problem still occur.

For example I have a User with date_joined equals 2016-10-16
12:17:44.270221-03 and when I select a date_hierarchy filter, that still
raise the same exception of:

NonExistentTimeError at /admin/auth/user/
2016-10-16 00:00:00


Even with an existing datetime.

The admin I did to test:
{{{
class UserAdmin(admin.ModelAdmin):
date_hierarchy = 'date_joined'
list_display = ('email', 'first_name', 'last_name', 'date_joined')
list_filter = ('is_staff', 'is_superuser')


admin.site.unregister(User)
admin.site.register(User, UserAdmin)
}}}

The internationalization settings:


{{{
LANGUAGE_CODE = 'pt-br'

TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = True

USE_L10N = True

USE_TZ = True
}}}

With TIME_ZONE = 'UTC' the problem doesn't occur.

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

Django

unread,
Nov 12, 2016, 2:39:34 PM11/12/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+--------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Hugo Tácito):

This also happens if we set a datetime to 2015-10-18. For example:
2015-10-18 10:45:29.270221-03
In 2015 at 10-18 was started the daylight savings at Brazil too.

https://www.timeanddate.com/time/change/brazil/sao-paulo?year=2015

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:3>

Django

unread,
Nov 12, 2016, 4:24:54 PM11/12/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+--------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Tim Graham):

Any idea what Django should do to resolve this?

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:4>

Django

unread,
Nov 12, 2016, 5:49:28 PM11/12/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+--------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Hugo Tácito):

Hello Tim,

It seems that the datetime truncation is too hard in the date_hierarchy
templatetag.

Changing this line:
https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_list.py#L385

to:
days = getattr(days, dates_or_datetimes)(field_name, 'second')

Probably will fix it.
I can also create a patch if you want.

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:5>

Django

unread,
Nov 13, 2016, 4:54:26 AM11/13/16
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Aymeric Augustin):

* stage: Unreviewed => Accepted


Comment:

The problem seems to stem from the fact that Django wants dates, but
fetches them as datetimes, and applies the converter for datetimes, which
causes an exception in that case.

It isn't possible to represent "2016-10-16 in local time in São Paulo" as
`datetime.datetime(2016, 10, 16,
tzinfo=pytz.timezone('America/Sao_Paulo'))` because that value doesn't
exist. The only proper way to represent it is `datetime.date(2016, 10,
16)`.

I believe the resolution should be along the lines of making the year /
month / day truncation expressions cast their result to a DateField
instead of a DateTimeField. Reducing the problem to a lower-level test
case may help.

It seems possible that the same problem could occur with the hour
truncation expression if some time zones have their DST between 1:30 and
2:30. I'm not sure what we could do about that; it seems much harder to
fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:6>

Django

unread,
Jan 5, 2017, 11:54:09 AM1/5/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* Attachment "djtest.zip" added.

Django

unread,
Jan 5, 2017, 11:54:47 AM1/5/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* cc: desecho@… (added)
* version: 1.10 => master


Comment:

I've attached a django project to reproduce the problem. Admin credentials
- admin/AiNeuw3uOhvei7da
To reproduce, open /admin/app/test/?date__month=10&date__year=2016

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:7>

Django

unread,
Jan 5, 2017, 2:28:41 PM1/5/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* has_patch: 0 => 1


Comment:

Added [https://github.com/django/django/pull/7797 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:8>

Django

unread,
Feb 6, 2017, 9:56:30 AM2/6/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:9>

Django

unread,
Feb 24, 2017, 10:24:30 AM2/24/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:10>

Django

unread,
Mar 6, 2017, 12:19:26 PM3/6/17
to django-...@googlegroups.com
#27475: Bug in admin with date_hierarchy and Daylight savings
-------------------------------+------------------------------------

Reporter: Hugo Tácito | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"e88d2dfcf4daa2b4ee451f518085413bb3b8deeb" e88d2df]:
{{{
#!CommitTicketReference repository=""
revision="e88d2dfcf4daa2b4ee451f518085413bb3b8deeb"
Fixed #27475 -- Fixed NonExistentTimeError crash in
ModelAdmin.date_hierarchy.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27475#comment:11>

Reply all
Reply to author
Forward
0 new messages