and it happens with all my models with some DateTimeField.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* severity: Normal => Release blocker
* cc: timo (added)
* needs_better_patch: => 0
* component: Uncategorized => Core (Other)
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
I can reproduce this on the tutorial with the following query:
`Poll.objects.datetimes('pub_date', 'month')` (Python 2.7, pytz 2013.8,
settings.USE_TZ=True). Tentatively marking as a release blocker as I don't
see anything wrong with that based on the documentation. On the other
hand, we have tests that seem to test the same thing, so wihout digging in
I'm unsure what the issue might be.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:1>
Comment (by timo):
{{{
>>> Poll.objects.datetimes('pub_date', 'month')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/timgraham/code/django/django/db/models/query.py", line 115,
in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/home/timgraham/code/django/django/db/models/query.py", line 140,
in __iter__
self._fetch_all()
File "/home/timgraham/code/django/django/db/models/query.py", line 962,
in _fetch_all
self._result_cache = list(self.iterator())
File "/home/timgraham/code/django/django/db/models/sql/compiler.py",
line 1089, in results_iter
datetime = timezone.make_aware(datetime, self.query.tzinfo)
AttributeError: 'DateTimeQuery' object has no attribute 'tzinfo'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:2>
Comment (by bmispelon):
Bisecting the error lead me to commit
70679243d1786e03557c28929f9762a119e3ac14, but it's not really obvious (to
me anyway) why that would have broken the feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:3>
Comment (by akaariai):
It is possible the above commit just makes the error loud instead of
hiding the error and returning silently []. Before the commit errors
inside queryset iteration led to empty list as result.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:4>
* cc: bmispelon (added)
Comment:
Replying to [comment:4 akaariai]:
> It is possible the above commit just makes the error loud instead of
hiding the error and returning silently []. Before the commit errors
inside queryset iteration led to empty list as result.
Indeed, this appears to be the case.
While digging, I also found out that the following code works:
{{{#!python
qs = Poll.objects.datetimes('pub_date', 'month')
list(qs)
repr(qs)
}}}
While this one doesn't (note how `repr` and `list` have been switched):
{{{#!python
qs = Poll.objects.datetimes('pub_date', 'month')
repr(qs)
list(qs)
}}}
This explains why this issue has been able to fall through the cracks:
iterating over a queryset is a much more common use-case than displaying
it as-is.
Unfortunately, I haven't been able to identify exactly where the problem
lies (I have a suspicion that it's got something to do with the `_clone`
method though) but I've managed to come up with a failing testcase (see
attached).
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:5>
Comment (by akaariai):
Yeah, the problem seem to be that when doing qs.datetimes() the
DateTimeQuery gets a tzinfo attribute (datetimes() end up in here:
https://github.com/django/django/blob/master/django/db/models/query.py#L1255),
but if the query gets cloned afterwards the tzinfo attribute will not get
cloned. The solution seems to be to write a custom .clone() for
DateTimeQuery.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:6>
* cc: loic@… (added)
* has_patch: 0 => 1
Comment:
PR https://github.com/django/django/pull/1919.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:7>
* status: new => assigned
* owner: nobody => aaugustin
Comment:
The patch looks appropriate.
The test could be simplified a bit with `now =
timezone.now().replace(microsecond=0)`.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:8>
* stage: Accepted => Ready for checkin
Comment:
Patch looks good.
It fixes the issue and the full test suite still passes after applying it.
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"17ed99f3a3eea4bd27fa34be59c3582616ed8079"]:
{{{
#!CommitTicketReference repository=""
revision="17ed99f3a3eea4bd27fa34be59c3582616ed8079"
Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning.
Thanks Enrique Martínez for the report and @bmispelon for the tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:10>
Comment (by Baptiste Mispelon <bmispelon@…>):
In [changeset:"67c30426c1370f5d6c39bd73888c3902c1c5f365"]:
{{{
#!CommitTicketReference repository=""
revision="67c30426c1370f5d6c39bd73888c3902c1c5f365"
[1.6.x] Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning.
Thanks Enrique Martínez for the report and @bmispelon for the tests.
Backport of 17ed99f3a3eea4bd27fa34be59c3582616ed8079 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:11>
Comment (by Loic Bistuer <loic.bistuer@…>):
In [changeset:"32e75803be8b3e9c35e6735c265125c4130ffabc"]:
{{{
#!CommitTicketReference repository=""
revision="32e75803be8b3e9c35e6735c265125c4130ffabc"
Fixed typo and slightly improved error message when db is missing time
zone definitions.
Refs #21432.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:12>
Comment (by Tim Graham <timograham@…>):
In [changeset:"3bb7de8c7c3f9d5de5426d94f45fe83b5d998357"]:
{{{
#!CommitTicketReference repository=""
revision="3bb7de8c7c3f9d5de5426d94f45fe83b5d998357"
[1.6.x] Fixed typo and slightly improved error message when db is missing
time zone definitions.
Refs #21432.
Backport of 32e75803be from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21432#comment:13>