mirror of https://github.com/django/django.git
[1.6.x] Fixed #21643 -- repeated execution of qs with F() + timedelta
Thanks Tim Graham for review and Tai Lee for the additional test to prove this was a regression in 1.6. Backport of7f2485b4d1
and8137215973
from master
This commit is contained in:
parent
f2b513c9e8
commit
5cda1d2702
|
@ -108,6 +108,7 @@ class SQLEvaluator(object):
|
|||
def evaluate_date_modifier_node(self, node, qn, connection):
|
||||
timedelta = node.children.pop()
|
||||
sql, params = self.evaluate_node(node, qn, connection)
|
||||
node.children.append(timedelta)
|
||||
|
||||
if timedelta.days == 0 and timedelta.seconds == 0 and \
|
||||
timedelta.microseconds == 0:
|
||||
|
|
|
@ -14,3 +14,7 @@ several bugs in 1.6.2:
|
|||
* Fixed ``AttributeError`` when using
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_create` with ``ForeignObject``
|
||||
(`#21566 <http://code.djangoproject.com/ticket/21566>`_).
|
||||
|
||||
* Fixed crash of ``QuerySet``\s that use ``F() + timedelta()`` when their query
|
||||
was compiled more once
|
||||
(`#21643 <http://code.djangoproject.com/ticket/21643>`_).
|
||||
|
|
|
@ -259,6 +259,20 @@ class FTimeDeltaTests(TestCase):
|
|||
self.days_long.append(e4.completed-e4.assigned)
|
||||
self.expnames = [e.name for e in Experiment.objects.all()]
|
||||
|
||||
def test_multiple_query_compilation(self):
|
||||
# Ticket #21643
|
||||
queryset = Experiment.objects.filter(end__lt=F('start') + datetime.timedelta(hours=1))
|
||||
q1 = str(queryset.query)
|
||||
q2 = str(queryset.query)
|
||||
self.assertEqual(q1, q2)
|
||||
|
||||
def test_query_clone(self):
|
||||
# Ticket #21643
|
||||
qs = Experiment.objects.filter(end__lt=F('start') + datetime.timedelta(hours=1))
|
||||
qs2 = qs.all()
|
||||
list(qs)
|
||||
list(qs2)
|
||||
|
||||
def test_delta_add(self):
|
||||
for i in range(len(self.deltas)):
|
||||
delta = self.deltas[i]
|
||||
|
|
Loading…
Reference in New Issue