Changeset 6760
- Timestamp:
- 11/29/07 20:29:25 (9 months ago)
- Files:
-
- django/branches/queryset-refactor/django/db/models/sql/query.py (modified) (2 diffs)
- django/branches/queryset-refactor/docs/db-api.txt (modified) (2 diffs)
- django/branches/queryset-refactor/tests/modeltests/many_to_one_null/models.py (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/null_queries/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/models/sql/query.py
r6755 r6760 680 680 lookup_type = parts.pop() 681 681 682 # Interpret '__exact=None' as the sql ' =NULL'; otherwise, reject all682 # Interpret '__exact=None' as the sql 'is NULL'; otherwise, reject all 683 683 # uses of None as a query value. 684 # FIXME: Weren't we going to change this so that '__exact=None' was the685 # same as '__isnull=True'? Need to check the conclusion of the mailing686 # list thread.687 if value is None and lookup_type != 'exact':688 raise ValueError("Cannot use None as a query value")684 if value is None: 685 if lookup_type != 'exact': 686 raise ValueError("Cannot use None as a query value") 687 lookup_type = 'isnull' 688 value = True 689 689 elif callable(value): 690 690 value = value() … … 709 709 col = join[LHS_JOIN_COL] 710 710 711 if (lookup_type == 'isnull' and value is True): 711 if lookup_type == 'isnull' and value is True and (len(join_list) > 1 or 712 len(join_list[0]) > 1): 712 713 # If the comparison is against NULL, we need to use a left outer 713 714 # join when connecting to the previous model. We make that django/branches/queryset-refactor/docs/db-api.txt
r6603 r6760 1138 1138 1139 1139 SELECT ... WHERE id = 14; 1140 SELECT ... WHERE id = NULL; 1140 SELECT ... WHERE id IS NULL; 1141 1142 **New in Django development version:** The semantics of ``id__exact=None`` have 1143 changed in the development version. Previously, it was (intentionally) 1144 converted to ``WHERE id = NULL`` at the SQL level, which would never match 1145 anything. It has now been changed to behave the same as ``id__isnull=True``. 1141 1146 1142 1147 iexact … … 1367 1372 1368 1373 SELECT ... WHERE pub_date IS NULL; 1369 1370 .. admonition:: ``__isnull=True`` vs ``__exact=None``1371 1372 There is an important difference between ``__isnull=True`` and1373 ``__exact=None``. ``__exact=None`` will *always* return an empty result1374 set, because SQL requires that no value is equal to ``NULL``.1375 ``__isnull`` determines if the field is currently holding the value1376 of ``NULL`` without performing a comparison.1377 1374 1378 1375 search django/branches/queryset-refactor/tests/modeltests/many_to_one_null/models.py
r5876 r6760 81 81 [<Article: Third>] 82 82 83 # We can achieve the same thing by filtering for the case where the reporter is 84 # None. 85 >>> Article.objects.filter(reporter=None) 86 [<Article: Third>] 87 83 88 # Set the reporter for the Third article 84 89 >>> r.article_set.add(a3) django/branches/queryset-refactor/tests/regressiontests/null_queries/models.py
r6730 r6760 25 25 >>> c2.save() 26 26 27 # Exact query with value None returns nothing (=NULL in sql) 27 # Exact query with value None returns nothing ("is NULL" in sql, but every 'id' 28 # field has a value). 28 29 >>> Choice.objects.filter(id__exact=None) 29 30 [] 31 32 Excluding the previous result returns everything. 33 >>> Choice.objects.exclude(id=None).order_by('id') 34 [<Choice: Choice: Because. in poll Q: Why? >, <Choice: Choice: Why Not? in poll Q: Why? >] 30 35 31 36 # Valid query, but fails because foo isn't a keyword
