jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting
https://django-polymorphic.readthedocs.io
Other
1.61k stars 275 forks source link

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

Open CelestialGuru opened 5 months ago

CelestialGuru commented 5 months ago

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.

j-antunes commented 5 months ago

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