Opened 8 years ago
Last modified 3 years ago
#28410 new Bug
query filter on date portion of datetime creates wrong parameters for mysql CONVERT_TZ function when used with a fixed offset timezone
Description (last modified by ) ¶
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.
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (6)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 8 years ago
Summary: | query filter on date portion of datetime creates wrong parameters for mysql CONVERT_TZ function and returns no results → query filter on date portion of datetime creates wrong parameters for mysql CONVERT_TZ function when used with a fixed offset timezone |
---|
comment:4 by , 8 years ago
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
comment:5 by , 6 years ago
Cc: | added |
---|
In master branch, I couldn't see a problem with this query. Doesn't timedelta(hours=-5)
work for your need? am I wrong?
from datetime import timedelta, timezone as datetime_timezone tz = datetime_timezone(timedelta(hours=-5)) timezone.activate(tz)
comment:6 by , 3 years ago
Cc: | added |
---|
I can reproduce the problem, although poking around the code left me wondering if there's a reason not to deprecate
get_fixed_timezone()
andFixedOffset
so we don't have to handle this additional case. Is there a reason you're preferring that rather than usingpytz
? I didn't see an explanation of theget_fixed_timezone()
's use case in Django's documentation.