Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

queryset-refactor: Fixed the "in" lookup type when using tuples.

Accidentally broken in r7170. Fixed #6772.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a81813fb4aec2e25850780c3846ad9743bf460ed 1 parent 2f45deb
@malcolmt malcolmt authored
View
3  django/db/models/fields/related.py
@@ -2,6 +2,7 @@
from django.db.models import signals, get_model
from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, get_ul_class
from django.db.models.related import RelatedObject
+from django.db.models.query_utils import QueryWrapper
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _
from django.utils.functional import curry
@@ -138,7 +139,7 @@ def pk_trace(value):
if hasattr(value, 'as_sql'):
sql, params = value.as_sql()
- return ('(%s)' % sql), params
+ return QueryWrapper(('(%s)' % sql), params)
if lookup_type == 'exact':
return [pk_trace(value)]
if lookup_type == 'in':
View
8 django/db/models/query_utils.py
@@ -15,6 +15,14 @@ class EmptyResultSet(Exception):
"""
pass
+class QueryWrapper(object):
+ """
+ A type that indicates the contents are an SQL fragment and the associate
+ parameters. Can be used to pass opaque data to a where-clause, for example.
+ """
+ def __init__(self, sql, params):
+ self.data = sql, params
+
class Q(tree.Node):
"""
Encapsulates filters as objects that can then be combined logically (using
View
5 django/db/models/sql/where.py
@@ -6,6 +6,7 @@
from django.utils import tree
from django.db import connection
from django.db.models.fields import Field
+from django.db.models.query_utils import QueryWrapper
from datastructures import EmptyResultSet, FullResultSet
# Connection types
@@ -110,8 +111,8 @@ def make_atom(self, child, qn):
params = field.get_db_prep_lookup(lookup_type, value)
else:
params = Field().get_db_prep_lookup(lookup_type, value)
- if isinstance(params, tuple):
- extra, params = params
+ if isinstance(params, QueryWrapper):
+ extra, params = params.data
else:
extra = ''
View
2  tests/modeltests/or_lookups/models.py
@@ -70,6 +70,8 @@ def __unicode__(self):
# You could also use "in" to accomplish the same as above.
>>> Article.objects.filter(pk__in=[1,2,3])
[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
+>>> Article.objects.filter(pk__in=(1,2,3))
+[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
>>> Article.objects.filter(pk__in=[1,2,3,4])
[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
Please sign in to comment.
Something went wrong with that request. Please try again.