#27930: The rhs attribute of the In lookup is not iterable anymore
-------------------------------------+-------------------------------------
Reporter: Mikalai | Owner: nobody
Radchuk |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords: subquery, lookup
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
During upgrade from Django 1.10 to 1.11b1, I've noticed that the `rhs`
attribute of the `In` lookup object is not iterable anymore. Previously it
was a `QuerySet` object, but now it contains a `Query` object.
I'm not sure if I can call it regression because
[[https://docs.djangoproject.com/en/1.11/ref/models/lookups/#django.db.models.Lookup.rhs|the
documentation]] for `Lookup.rhs` says that rhs "can be a plain value, or
something that compiles into SQL, typically an F() object or a QuerySet.".
So de jure everything is ok :) I've decided to report it anyway, because
it looks like it related to new feature
([[https://docs.djangoproject.com/en/1.11/releases/1.11/#subquery-
expressions|Subquery expressions]]), so maybe it is not expected
behaviour.
This snippet works on Django 1.9 and 1.10 but fails on 1.11b1 and on the
`stable/1.11.x` branch (I've tried on:
[[https://github.com/django/django/commit/9924c8a8b0f4281ba018ca3292ed78718fabe362|9924c8a]]).
{{{
#!python
from django.db.models.query import QuerySet
from django.db.models.lookups import Lookup
from django.db.models.sql.where import WhereNode
from demo.models import MyModel as SomeModel
# I think it will work with any subquery
qs = SomeModel.objects.filter(pk__in=SomeModel.objects.filter(pk__gte=10))
where_node = qs.query.where
assert isinstance(where_node, WhereNode)
lookup = where_node.children[0]
assert isinstance(lookup, Lookup)
rhs_value = lookup.rhs
try:
assert isinstance(rhs_value, QuerySet), "Expected type: %s. Actual
type: %s" % (QuerySet, type(rhs_value))
except AssertionError:
raise
else:
print("Ok")
}}}
Replace `MyModel` with any model definition
--
Ticket URL: <https://code.djangoproject.com/ticket/27930>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.3ea95399de17aab1a7f804ccc75c062f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.