Opened 8 years ago

Closed 8 years ago

#27930 closed Bug (invalid)

The rhs attribute of the In lookup is not iterable anymore

Reported by: Mikalai Radchuk Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords: subquery, lookup
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 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 (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: 9924c8a).

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

Change History (3)

comment:1 by Tim Graham, 8 years ago

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?

comment:2 by Mikalai Radchuk, 8 years ago

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!

comment:3 by Simon Charette, 8 years ago

Resolution: invalid
Status: newclosed

Thanks for the report Mikalai, as Tim mentioned I think this shouldn't be considered a regression given it's only internal API changes.

Note: See TracTickets for help on using tickets.
Back to Top