Skip to content
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

Check if child node is Q instance for subquery expressions #572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CelestialGuru
Copy link

Fixes bug when using Exists subqueries which are or-ed together:

SomeModel.objects.filter(
   Exists(RelatedModelA.objects.filter(some_model=OuterRef("pk"))
   | Exists(RelatedModelB.objects.filter(some_model=OuterRef("pk"))
)

This is done usually for performance reasons, but it is a valid queryset. Exist instances ored together like this creates a Q instance, but the children are not themselves Q instances. They are Exists instances.

Oring Exists() subqeries together "Exists() | Exists()" creates a Q instance, but not one which has Q node children.
@j-antunes
Copy link
Contributor

Thanks for opening a PR. Could you add the following:

  • A unit test to cover your changes
  • In your PR you change else to an elif, could you add another else so that in case none of the conditions are met, it will raise an exception or return something else.
    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants