[Django] #28410: query filter on date portion of datetime creates wrong parameters for mysql CONVERT_TZ function and returns no results

24 views
Skip to first unread message

Django

unread,
Jul 18, 2017, 10:53:18 AM7/18/17
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function and returns no results
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
donaldinho |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) | Keywords: timezone date
Severity: Normal | filter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I am setting the timezone

{{{
tz = timezone.get_fixed_timezone(-300)
timezone.activate(tz)
}}}

then I apply the filter. search_date is just a string submitted by the
client

{{{
matches = query.filter(startDateTime__date=datetime.strptime(search_date,
'%Y-%m-%d').date())
}}}

the where clause that is produced is
{{{
DATE(CONVERT_TZ(`central_soccer_match`.`startDateTime`, 'UTC', '-0500')) =
'2017-07-18'
}}}

where as it should be

{{{
DATE(CONVERT_TZ(`central_soccer_match`.`startDateTime`, 'UTC', '-05:00'))
= '2017-07-18'
}}}

note the colon in the timezone we are converting to.

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

Django

unread,
Jul 18, 2017, 10:56:50 AM7/18/17
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function and returns no results
-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage:
filter | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Old description:

> I am setting the timezone
>
> {{{
> tz = timezone.get_fixed_timezone(-300)
> timezone.activate(tz)
> }}}
>
> then I apply the filter. search_date is just a string submitted by the
> client
>
> {{{
> matches = query.filter(startDateTime__date=datetime.strptime(search_date,
> '%Y-%m-%d').date())
> }}}
>
> the where clause that is produced is
> {{{
> DATE(CONVERT_TZ(`central_soccer_match`.`startDateTime`, 'UTC', '-0500'))
> = '2017-07-18'
> }}}
>
> where as it should be
>
> {{{
> DATE(CONVERT_TZ(`central_soccer_match`.`startDateTime`, 'UTC', '-05:00'))
> = '2017-07-18'
> }}}
>
> note the colon in the timezone we are converting to.

New description:

I am setting the timezone

{{{
tz = timezone.get_fixed_timezone(-300)
timezone.activate(tz)
}}}

then I apply the filter. search_date is just a string submitted by the
client

{{{
matches = query.filter(startDateTime__date=datetime.strptime(search_date,
'%Y-%m-%d').date())
}}}

the where clause that is produced is
{{{

DATE(CONVERT_TZ(`match`.`startDateTime`, 'UTC', '-0500')) = '2017-07-18'
}}}

where as it should be

{{{
DATE(CONVERT_TZ(match`.`startDateTime`, 'UTC', '-05:00')) = '2017-07-18'
}}}

note the colon in the timezone we are converting to.

--

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

Django

unread,
Jul 18, 2017, 3:39:50 PM7/18/17
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function and returns no results
-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage: Accepted
filter |
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


Comment:

I can reproduce the problem, although poking around the code left me
wondering if there's a reason not to deprecate `get_fixed_timezone()` and
`FixedOffset` so we don't have to handle this additional case. Is there a
reason you're preferring that rather than using `pytz`? I didn't see an
explanation of the `get_fixed_timezone()`'s use case in Django's
documentation.

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

Django

unread,
Jul 18, 2017, 3:40:57 PM7/18/17
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function when used with a fixed offset timezone

-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage: Accepted
filter |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Jul 19, 2017, 4:52:38 AM7/19/17
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function when used with a fixed offset timezone
-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage: Accepted
filter |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by donaldinho):

I think I used get_fixed_timezone because I had the clients offset
provided by javascript in minutes rather than an explicit timezone and I
couldn't see a way to create a tzinfo class any other way

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

Django

unread,
May 30, 2019, 10:08:34 AM5/30/19
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function when used with a fixed offset timezone
-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage: Accepted
filter |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* cc: Can Sarıgöl (added)


Comment:

In master branch, I couldn't see a problem with this query. Doesn't
{{{timedelta(hours=-5)}}} work for your need? am I wrong?

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

Django

unread,
Oct 4, 2021, 5:43:28 AM10/4/21
to django-...@googlegroups.com
#28410: query filter on date portion of datetime creates wrong parameters for mysql
CONVERT_TZ function when used with a fixed offset timezone
-------------------------------------+-------------------------------------
Reporter: donaldinho | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: timezone date | Triage Stage: Accepted
filter |
Has patch: 0 | Needs documentation: 0

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

* cc: Carlton Gibson (added)


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

Reply all
Reply to author
Forward
0 new messages