If I try to search for that row with
{{{#!python
day = Calendar.objects.filter(day_date=date(2015,1,18))
}}}
I get SQL with the following WHERE clause:
{{{#!sql
WHERE day_date = '2015-01-18 00:00:00'
}}}
, i.e. it doesn't contain milliseconds part. As a consequence, the row is
not found. According to http://www.sqlite.org/datatype3.html, the text
representation of datetime values in SQLite should have milliseconds part.
In MS SQL it works fine (I use django-pyodbc-azure driver).
The workaround is:
{{{#!python
dt = datetime(2015,1,18) # datetime, not date
day = Calendar.objects.filter(day_date__lt=day+timedelta(seconds=1),
day_date__gt=day-timedelta(seconds=1))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24176>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24176#comment:1>
Comment (by shaib):
Hi, thanks for your report.
Can you please try these two variations:
a) `filter(day_date=datetime(2015,1,18))`
b) The whole thing on a newer Django -- 1.6 now gets important (that is,
security or data-loss) fixes only, and I don't think this qualifies.
Thanks again.
--
Ticket URL: <https://code.djangoproject.com/ticket/24176#comment:2>
* version: 1.6 => 1.7
Comment:
The bug still exists in Django 1.7.3, and
{{{filter(day_date=datetime(2015,1,18))}}} doesn't change anything.
--
Ticket URL: <https://code.djangoproject.com/ticket/24176#comment:3>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24176#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
Since Django 1.9, the query should force to date with:
`Calendar.objects.filter(day_date__date=date(2015,1,18))`
--
Ticket URL: <https://code.djangoproject.com/ticket/24176#comment:5>