Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11886 -- Corrected handling of F() expressions that use parent…

…heses. Thanks to Brent Hagany for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d56c1ab7f07eeaae3a0fc996169be7cae6a94bf4 1 parent f3af2d9
Russell Keith-Magee authored September 16, 2009
2  django/db/models/sql/expressions.py
@@ -66,7 +66,7 @@ def evaluate_node(self, node, qn):
66 66
             else:
67 67
                 sql, params = '%s', (child,)
68 68
 
69  
-            if hasattr(child, 'children') > 1:
  69
+            if len(getattr(child, 'children', [])) > 1:
70 70
                 format = '(%s)'
71 71
             else:
72 72
                 format = '%s'
10  tests/modeltests/expressions/models.py
@@ -56,6 +56,16 @@ def __unicode__(self):
56 56
 >>> company_query
57 57
 [{'num_chairs': 2302, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 5, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 34, 'name': u'Test GmbH', 'num_employees': 32}]
58 58
 
  59
+# Law of order of operations is followed
  60
+>>> _ =company_query.update(num_chairs=F('num_employees') + 2 * F('num_employees'))
  61
+>>> company_query
  62
+[{'num_chairs': 6900, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 9, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 96, 'name': u'Test GmbH', 'num_employees': 32}]
  63
+
  64
+# Law of order of operations can be overridden by parentheses
  65
+>>> _ =company_query.update(num_chairs=((F('num_employees') + 2) * F('num_employees')))
  66
+>>> company_query
  67
+[{'num_chairs': 5294600, 'name': u'Example Inc.', 'num_employees': 2300}, {'num_chairs': 15, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 1088, 'name': u'Test GmbH', 'num_employees': 32}]
  68
+
59 69
 # The relation of a foreign key can become copied over to an other foreign key.
60 70
 >>> Company.objects.update(point_of_contact=F('ceo'))
61 71
 3

0 notes on commit d56c1ab

Please sign in to comment.
Something went wrong with that request. Please try again.