-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Fixed #36210 -- Allowed Subquery usage in further lookups against composite pks. #19459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -1756,6 +1756,7 @@ def __init__(self, queryset, output_field=None, **extra): | |||
# Allow the usage of both QuerySet and sql.Query objects. | |||
self.query = getattr(queryset, "query", queryset).clone() | |||
self.query.subquery = True | |||
self.template = extra.pop("template", self.template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately avoided adding tests for extra
, given that discussion in ticket-35459 is ongoing. There is of course implicit coverage that a self.template
attribute exists.
This comment was marked as outdated.
This comment was marked as outdated.
82bdc88
to
8179ce8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
9740fa8
to
8cd60ac
Compare
def as_oracle(self, compiler, connection): | ||
""" | ||
Regardless of whether a subquery has been limited to return | ||
a single row, this error is raised for <, <=, >, and >=: | ||
ORA-01796: this operator cannot be used with lists | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An earlier version of this PR aimed to guard for subqueries inside get_fallback_sql()
, since I was seeing Query object is not iterable
on for val in self.rhs
, but even the versions of Oracle that support tuple lookups throw this ORA-01796 error, so I just decided to guard oracle. If there are other vendors with get_fallback_sql()
methods, they may need adjusting to handle subqueries. Open to ideas here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent a bit of time with the latest versions of Oracle so I have no ideas to offer.
8cd60ac
to
57bbeaf
Compare
This comment was marked as outdated.
This comment was marked as outdated.
def as_oracle(self, compiler, connection): | ||
""" | ||
Regardless of whether a subquery has been limited to return | ||
a single row, this error is raised for <, <=, >, and >=: | ||
ORA-01796: this operator cannot be used with lists | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent a bit of time with the latest versions of Oracle so I have no ideas to offer.
57bbeaf
to
f5fe954
Compare
f5fe954
to
572c665
Compare
This comment was marked as outdated.
This comment was marked as outdated.
572c665
to
4dbd4e1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
4dbd4e1
to
58e8073
Compare
…posite pks. Follow-up to 8561100. co-authored-by: Simon Charette <charette.s@gmail.com>
58e8073
to
9550460
Compare
def as_sql(self, compiler, connection): | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oracle 19 was failing because the two mixins (TupleLookupMixin
and TupleComparisonMixin
were not ordered correctly). Rather than have two mixins, which seems a little fragile, I just brought the new logic here, and guarded with an isinstance
check. Seems like a pick your thorn thing. 🤷♂️
buildbot, test on oracle. |
Trac ticket number
ticket-36210
Branch description
Following-up to ticket-36181 (#19160), which added support for
pk__in=Subquery(...
for composite primary keys, now other lookups besidesin
are supported, e.g.exact
.Because lookups besides
in
require limiting subqueries to a single result, handling this correctly uncovered situations where cardinality violations were flying under the radar, so a preparatory commit fixes correctness in some tests.Checklist
main
branch.