summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-06-08 00:54:28 +0000
committerHonza Král <honza.kral@gmail.com>2009-06-08 00:54:28 +0000
commit3e625f26672a0f886fbb47407d140c3ccf74fdaf (patch)
tree957cb68fb8d896cdc1e92e372610c4f942c0e5a3 /django/db/models/sql
parent7b14625d0d9c8dc4df87c5354c856e6f5ed3ef60 (diff)
[soc2009/model-validation] Merged to trunk at r10941
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10944 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index d290d60e63..23f99e41ad 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -635,10 +635,10 @@ class BaseQuery(object):
# models.
workset = {}
for model, values in seen.iteritems():
- for field, f_model in model._meta.get_fields_with_model():
+ for field in model._meta.local_fields:
if field in values:
continue
- add_to_dict(workset, f_model or model, field)
+ add_to_dict(workset, model, field)
for model, values in must_include.iteritems():
# If we haven't included a model in workset, we don't add the
# corresponding must_include fields for that model, since an
@@ -657,6 +657,12 @@ class BaseQuery(object):
# included any fields, we have to make sure it's mentioned
# so that only the "must include" fields are pulled in.
seen[model] = values
+ # Now ensure that every model in the inheritance chain is mentioned
+ # in the parent list. Again, it must be mentioned to ensure that
+ # only "must include" fields are pulled in.
+ for model in orig_opts.get_parent_list():
+ if model not in seen:
+ seen[model] = set()
for model, values in seen.iteritems():
callback(target, model, values)
@@ -1619,10 +1625,14 @@ class BaseQuery(object):
entry.negate()
self.where.add(entry, AND)
break
- elif not (lookup_type == 'in' and not value) and field.null:
+ elif not (lookup_type == 'in'
+ and not hasattr(value, 'as_sql')
+ and not hasattr(value, '_as_sql')
+ and not value) and field.null:
# Leaky abstraction artifact: We have to specifically
# exclude the "foo__in=[]" case from this handling, because
# it's short-circuited in the Where class.
+ # We also need to handle the case where a subquery is provided
entry = self.where_class()
entry.add((Constraint(alias, col, None), 'isnull', True), AND)
entry.negate()