[Django] #27930: The rhs attribute of the In lookup is not iterable anymore

44 views
Skip to first unread message

Django

unread,
Mar 11, 2017, 2:08:42 PM3/11/17
to django-...@googlegroups.com
#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.

Django

unread,
Mar 11, 2017, 2:45:30 PM3/11/17
to django-...@googlegroups.com
#27930: The rhs attribute of the In lookup is not iterable anymore
-------------------------------------+-------------------------------------
Reporter: Mikalai Radchuk | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:

Keywords: subquery, lookup | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 12, 2017, 6:39:29 AM3/12/17
to django-...@googlegroups.com
#27930: The rhs attribute of the In lookup is not iterable anymore
-------------------------------------+-------------------------------------
Reporter: Mikalai Radchuk | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: subquery, lookup | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 12, 2017, 10:00:12 PM3/12/17
to django-...@googlegroups.com
#27930: The rhs attribute of the In lookup is not iterable anymore
-------------------------------------+-------------------------------------
Reporter: Mikalai Radchuk | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: subquery, lookup | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* 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>

Reply all
Reply to author
Forward
0 new messages