Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #11886 -- Corrected handling of F() expressions that us…

…e parentheses. Thanks to Brent Hagany for the report.

Merge of r11581 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a2c7fe52a8e2d938621d1f7607e3d8a7a84ebf1e 1 parent 6febb7e
Russell Keith-Magee freakboy3742 authored
2  django/db/models/sql/expressions.py
View
@@ -66,7 +66,7 @@ def evaluate_node(self, node, qn):
else:
sql, params = '%s', (child,)
- if hasattr(child, 'children') > 1:
+ if len(getattr(child, 'children', [])) > 1:
format = '(%s)'
else:
format = '%s'
10 tests/modeltests/expressions/models.py
View
@@ -56,6 +56,16 @@ def __unicode__(self):
>>> company_query
[{'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}]
+# Law of order of operations is followed
+>>> _ =company_query.update(num_chairs=F('num_employees') + 2 * F('num_employees'))
+>>> company_query
+[{'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}]
+
+# Law of order of operations can be overridden by parentheses
+>>> _ =company_query.update(num_chairs=((F('num_employees') + 2) * F('num_employees')))
+>>> company_query
+[{'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}]
+
# The relation of a foreign key can become copied over to an other foreign key.
>>> Company.objects.update(point_of_contact=F('ceo'))
3
Please sign in to comment.
Something went wrong with that request. Please try again.