﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27930	The rhs attribute of the In lookup is not iterable anymore	Mikalai Radchuk	nobody	"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"	Bug	closed	Database layer (models, ORM)	1.11	Normal	invalid	subquery, lookup		Unreviewed	0	0	0	0	0	0
