-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #36464 -- Fixed tuple in subquery lookup when missing native support. #19565
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
Conversation
buildbot, test on oracle. |
Thank you for picking this up Simon ⭐ I have been trying and failing to run the mssql-django tests following the contributing instructions using docker to run the tests Error in case this is obvious
This means I'm struggling to confirm the issue is fixed. |
Just a note that I have managed to confirm that after this change |
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.
Thank you ⭐
👍👍 |
b21ab32
to
a9fc176
Compare
f5bbf9f
to
2bd06ea
Compare
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.
Thank you @charettes, this looks great! 🌟
buildbot, test on oracle. |
1 similar comment
buildbot, test on oracle. |
There is a failure occurring in Oracle CI. This test (which I tweaked slightly in a throwaway commit to be able to see the whole result): def test_query_does_not_mutate(self):
"""
Recompiling the same subquery doesn't mutate it.
"""
queryset = Friendship.objects.filter(to_friend__in=Person.objects.all())
self.assertEqual(str(queryset.query), str(queryset.query)) fails the assertion because the first str call is: SELECT "foreign_object_friendship"."id",
"foreign_object_friendship"."from_friend_country_id",
"foreign_object_friendship"."from_friend_id",
"foreign_object_friendship"."to_friend_country_id",
"foreign_object_friendship"."to_friend_id"
FROM "foreign_object_friendship"
WHERE EXISTS(SELECT 1 AS "A"
FROM "foreign_object_person"
WHERE ( "foreign_object_friendship"."to_friend_country_id" = (
"foreign_object_person"."person_country_id" )
AND "foreign_object_friendship"."to_friend_id" = (
"foreign_object_person"."id" ) )
FETCH first 1 ROWS only) and the second: SELECT "foreign_object_friendship"."id",
"foreign_object_friendship"."from_friend_country_id",
"foreign_object_friendship"."from_friend_id",
"foreign_object_friendship"."to_friend_country_id",
"foreign_object_friendship"."to_friend_id"
FROM "foreign_object_friendship"
WHERE EXISTS(SELECT 1 AS "A"
FROM "foreign_object_person"
WHERE ( "foreign_object_friendship"."to_friend_country_id" = (
"foreign_object_person"."person_country_id" )
AND "foreign_object_friendship"."to_friend_id" =
( "foreign_object_person"."id" )
AND "foreign_object_friendship"."to_friend_country_id" =
(
"foreign_object_person"."person_country_id" )
AND "foreign_object_friendship"."to_friend_id" = (
"foreign_object_person"."id" ) )
FETCH first 1 ROWS only) showing there is an extra: AND "foreign_object_friendship"."to_friend_id" =
( "foreign_object_person"."id" )
AND "foreign_object_friendship"."to_friend_country_id" =
(
"foreign_object_person"."person_country_id" ) in the second one. @charettes I don't have the capacity to debug before tomorrow, would you have any idea from the top of your head of why is this occurring? feels like a lack of cloning somewhere. |
Sorry for the trouble, there use to be cloning in place but when I removed the |
Yeah, I know, sorry about that, it's so hard to properly review without a way to run locally. I've tried to have a working Oracle 19 setup locally but haven't succeeded. |
@charettes no worries, I managed a way to reproduce. I'm adding an analogous
|
…support. When native support for tuple lookups is missing in a DB backend, it can be emulated with an EXISTS clause. This is controlled by the backend feature flag "supports_tuple_lookups". The mishandling of subquery right-hand side in `TupleIn` (added to support `CompositePrimaryKey` in Refs django#373) was likely missed because the only core backend we test with the feature flag disabled (Oracle < 23.4) supports it natively. Thanks to Nandana Raol for the report, and to Sarah Boyce, Jacob Walls, and Natalia Bidart for reviews.
buildbot, test on oracle. |
Trac ticket number
ticket-36464
Branch description
When native support is missing it can be emulated with an EXISTS clause.
The mishandling of subquery right-hand-side was likely missed because the only core backend we happen to test with the
supports_tuple_lookups
feature disabled (Oracle < 23.4) supports it natively.Thanks @NandanaRaol for the report against SQL Server.