Browse files

[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 of 7f2485b and 8137215 from master
  • Loading branch information...
1 parent f2b513c commit 5cda1d27027ea74d8a1b53e43bef697cd4426e9a @despawnerer despawnerer committed with timgraham Dec 21, 2013
Showing with 19 additions and 0 deletions.
  1. +1 −0 django/db/models/sql/expressions.py
  2. +4 −0 docs/releases/1.6.3.txt
  3. +14 −0 tests/expressions_regress/tests.py
View
1 django/db/models/sql/expressions.py
@@ -108,6 +108,7 @@ def evaluate_leaf(self, node, qn, connection):
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:
View
4 docs/releases/1.6.3.txt
@@ -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>`_).
View
14 tests/expressions_regress/tests.py
@@ -259,6 +259,20 @@ def setUp(self):
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]

0 comments on commit 5cda1d2

Please sign in to comment.