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.
Comment (by Tim Graham):
My guess is that this is due to 1bc249c2a67c24fcd28436c85388eff1d826e305.
I think this falls into a private API change hence no release notes are
required, but could you describe your use case?
--
Ticket URL: <https://code.djangoproject.com/ticket/27930#comment:1>
Comment (by Mikalai Radchuk):
Hi Tim,
In Wagtail CMS we have a search back-end that transforms lookups from a
`QuerySet` object into Elasticsearch Query DSL (which is JSON, actually).
I know that it is a private API and we will fix it on Wagtail's side.
I was not sure that it is expected behaviour. so decided to double check.
Feel free to close this ticket, if it looks good to you.
And thank you for your help!
--
Ticket URL: <https://code.djangoproject.com/ticket/27930#comment:2>
* status: new => closed
* resolution: => invalid
Comment:
Thanks for the report Mikalai, as Tim mentioned I think this shouldn't be
considered a regression given it's only internal API changes.
--
Ticket URL: <https://code.djangoproject.com/ticket/27930#comment:3>