[Django] #29724: Bug with time filter in django admin

30 views
Skip to first unread message

Django

unread,
Aug 29, 2018, 10:14:52 AM8/29/18
to django-...@googlegroups.com
#29724: Bug with time filter in django admin
-----------------------------------------+------------------------
Reporter: freakaton | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-----------------------------------------+------------------------
When I authorized by user with not-UTC timezone, like ''Los-
Angeles/America'' , and open filter by date in month, I see one extra day,
that follows to the first day of the previous month

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

Django

unread,
Aug 29, 2018, 10:15:20 AM8/29/18
to django-...@googlegroups.com
#29724: Bug with time filter in django admin
-------------------------------+--------------------------------------

Reporter: freakaton | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
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: 1
-------------------------------+--------------------------------------
Changes (by freakaton):

* Attachment "Снимок экрана 2018-08-29 в 16.59.28.png" added.

representation of bug

Django

unread,
Aug 29, 2018, 1:52:17 PM8/29/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------+--------------------------------------
Reporter: Lavrenov Ivan | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
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: 1
-------------------------------+--------------------------------------

Comment (by Tim Graham):

Could you be more specific about how to reproduce this? I thought you
meant `TIME_ZONE = 'Los-Angeles/America'` but I get "Incorrect timezone
setting". Which database are you using?

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

Django

unread,
Aug 29, 2018, 2:32:45 PM8/29/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------+--------------------------------------
Reporter: Lavrenov Ivan | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
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: 1
-------------------------------+--------------------------------------

Comment (by Lavrenov Ivan):

The timezone is '' America/Los_Angeles'', sorry for inaccuracy.
I'm using Mysql database. I think it is something сonnected with
converstion to local time. I have a record, which in UTC in the 1st
September, but in local time it is still in the 31 August.

P.S. Values stored in UTC format

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

Django

unread,
Aug 30, 2018, 4:03:47 AM8/30/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------+--------------------------------------
Reporter: Lavrenov Ivan | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
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: 1
-------------------------------+--------------------------------------

Comment (by Lavrenov Ivan):

Replying to [comment:1 Tim Graham]:


> Could you be more specific about how to reproduce this? I thought you
meant `TIME_ZONE = 'Los-Angeles/America'` but I get "Incorrect timezone
setting". Which database are you using?

The timezone is America/Los_Angeles, sorry for inaccuracy.


I'm using Mysql database. I think it is something сonnected with
converstion to local time. I have a record, which in UTC in the 1st
September, but in local time it is still in the 31 August.
P.S. Values stored in UTC format

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

Django

unread,
Aug 30, 2018, 4:04:33 AM8/30/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------+--------------------------------------
Reporter: Lavrenov Ivan | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
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: 1
-------------------------------+--------------------------------------
Description changed by Lavrenov Ivan:

Old description:

> When I authorized by user with not-UTC timezone, like ''Los-
> Angeles/America'' , and open filter by date in month, I see one extra
> day, that follows to the first day of the previous month

New description:

When I authorized by user with not-UTC timezone, like

''America/Los_Angeles'' , and open filter by date in month, I see one


extra day, that follows to the first day of the previous month

--

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

Django

unread,
Sep 3, 2018, 3:52:50 AM9/3/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------+------------------------------------
Reporter: Lavrenov Ivan | 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: 1
-------------------------------+------------------------------------
Changes (by Carlton Gibson):

* version: 2.0 => master
* stage: Unreviewed => Accepted


Comment:

Yes. I can reproduce this.

1. Have a DateTimeField in `date_hierarchy` (and optionally `list_display)
2. Create an object in the DB for midnight 1st Sep (UTC).
3. Set project TIME_ZONE = 'America/Los_Angeles'

* Test object is show in list at Aug 31 5PM.
* Date hierarchy choice is created for 1st September
* Link for that is incorrect:
`?<field>__day=1&<field>__month=8&<field>__year=2018`, i.e. Aug 1st.

Presumably error is in
[https://github.com/django/django/blob/231c595bde342e507091167387fba7ba1882b9c9/django/contrib/admin/templatetags/admin_list.py#L354
`date_hierarchy()` template tag function].

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

Django

unread,
Sep 12, 2018, 12:56:01 AM9/12/18
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned

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: 1
-------------------------------------+-------------------------------------
Changes (by Alexander Holmbäck):

* owner: nobody => Alexander Holmbäck
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* status: new => assigned


Comment:

[https://github.com/django/django/pull/10380, PR]

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

Django

unread,
Sep 3, 2019, 2:10:20 AM9/3/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.

-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
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: 1
-------------------------------------+-------------------------------------

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

Django

unread,
Sep 3, 2019, 2:11:48 AM9/3/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
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: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Duplicate reported in #30749

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

Django

unread,
Sep 3, 2019, 2:16:19 PM9/3/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
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: 1
-------------------------------------+-------------------------------------

Comment (by yab):

Two distinct date_hierarchy bugs : one relate to TZ effects and one
related to DST effects :

#29724 (TZ matter)
When year and month lookup are chosen, if you have an event late in last
day of the month that is first day of next month in UTC, queryset.dates
method gives a date_hierarchy choice for next month 1st.
It seems it can be solved modifiyng
admin/contrib/templatetags/admin_list.py this way, using **queryset.filter
and lists that may be very slow** :
Needs importing:
{{{
from django.utils.timezone import make_naive
from django.conf import settings
}}}
and after "elif year_lookup and month_lookup:":
{{{
elif year_lookup and month_lookup:
### This is a way to avoid using queryset.dates
fucntion, which was giving naive datetimes with problems when the
monthrange is different between utc and localtime.

month_filter=field_name+'__month'
year_filter=field_name+'__year'
dates_or_datetimes =
cl.model.objects.filter(**{year_filter:year_lookup,
month_filter:month_lookup}).values_list(field_name, flat=True).distinct()

days = dates_or_datetimes
if isinstance(dates_or_datetimes[0],
datetime.datetime) and settings.USE_TZ:
day_list = []
days = []
for day in dates_or_datetimes:
if make_naive(day).day not in
day_list:
day_list.append(make_naive(day).day)
days.append(make_naive(day))
###
}}}

###30749 (DST matter)
If the month selected by date_hierarchy is the month of the DST, the
objects of the last day of the month does not appear in the changelist.
Changing the way "from_date" is set after ''elif month'' line 165 solves
my problem: Instead of just adding 32 days with timedelta, I use
make_aware with tzinfo=None. That way the to_date is set to the correct
date and time.
{{{
elif month:
### The tzinfo changes between
first and last day of the month when DST applies. That's why we need to
make_aware to_date separately from from_date
to_date = make_aware((from_date +
timedelta(days=32)).replace(day=1,tzinfo=None))
}}}

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

Django

unread,
Sep 3, 2019, 6:31:30 PM9/3/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_tests: 0 => 1


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

Django

unread,
Sep 4, 2019, 1:26:00 AM9/4/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

OK, thanks for the follow-up yab. TBH I'm still inclined to view these as
the same issue: incorrect collection of items at time-period boundaries
(demonstrated with DST and TZ examples). However... one-ticket/two-tickets
is not so important.

More is that, we need to make sure we have test cases for both these types
of example, and then we can make sure any fix addresses both of those.

Super. 👍

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

Django

unread,
Sep 4, 2019, 6:53:00 PM9/4/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by yab):

OK, my proposal passes existing tests. Not sure how to create specific
test cases for that purpose. My proposal is above and there :
https://github.com/yab228/django/blob/master/django/contrib/admin/templatetags/admin_list.py

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:12>

Django

unread,
Sep 5, 2019, 2:01:29 AM9/5/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

yab: please make a pull request with your suggested changes. (See the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-style contributing guide].)

For tests, please **add** a test case with the example(s) here. Presumably
they should fail with the exisiting code, showing the bug, and then pass
with your patch applied.

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:13>

Django

unread,
Sep 5, 2019, 12:31:32 PM9/5/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by yab):

Hello Carlton,
Here is the pull request :
[https://github.com/django/django/pull/11747]
It now passes the test cases written by ahbk in PR ticket_29724
[https://github.com/ahbk/django/tree/ticket_29724], called
test_date_hierarchy_local_date_differ_from_utc and test_choice_links_date.

Replying to [comment:13 Carlton Gibson]:


> yab: please make a pull request with your suggested changes. (See the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-style contributing guide].)
>
> For tests, please **add** a test case with the example(s) here.
Presumably they should fail with the exisiting code, showing the bug, and
then pass with your patch applied.

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:14>

Django

unread,
Oct 29, 2019, 4:53:07 AM10/29/19
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------------+-------------------------------------
Reporter: Lavrenov Ivan | Owner: Alexander
| Holmbäck
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

#30922 was also a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:15>

Django

unread,
Feb 18, 2020, 9:42:18 AM2/18/20
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------+------------------------------------------
Reporter: Lavrenov Ivan | Owner: Hasan Ramezani

Type: Bug | Status: assigned
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: 1
-------------------------------+------------------------------------------
Changes (by Hasan Ramezani):

* owner: Alexander Holmbäck => Hasan Ramezani
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:16>

Django

unread,
Mar 20, 2020, 8:18:28 AM3/20/20
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------+------------------------------------------
Reporter: Lavrenov Ivan | Owner: Hasan Ramezani
Type: Bug | Status: assigned
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: 1
-------------------------------+------------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"53b6a466d89f972aa435fe7b5135e9b501ce68ee" 53b6a466]:
{{{
#!CommitTicketReference repository=""
revision="53b6a466d89f972aa435fe7b5135e9b501ce68ee"
Refs #29724 -- Added is_dst parameter to QuerySet.datetimes().

Thanks Simon Charette for the review and Mariusz Felisiak for tests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:17>

Django

unread,
Mar 25, 2020, 4:24:10 PM3/25/20
to django-...@googlegroups.com
#29724: Admin date_hierarchy filter by month displays an extra day at timezone
boundary.
-------------------------------+------------------------------------------
Reporter: Lavrenov Ivan | Owner: Hasan Ramezani
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: 1
-------------------------------+------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"55cdf6c52db07f29128741b8734a523ed042e465" 55cdf6c5]:
{{{
#!CommitTicketReference repository=""
revision="55cdf6c52db07f29128741b8734a523ed042e465"
Fixed #29724 -- Fixed timezone handling in ModelAdmin.date_hierarchy
queries.

Thanks Alexander Holmbäck for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29724#comment:18>

Reply all
Reply to author
Forward
0 new messages