django-polymorphic icon indicating copy to clipboard operation
django-polymorphic copied to clipboard

Check if child node is Q instance for subquery expressions

Open CelestialGuru opened this issue 1 year ago • 1 comments

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.

CelestialGuru avatar Jan 31 '24 03:01 CelestialGuru

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

j-antunes avatar Jan 31 '24 16:01 j-antunes