django-polymorphic
django-polymorphic copied to clipboard
Check if child node is Q instance for subquery expressions
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.
Thanks for opening a PR. Could you add the following:
- A unit test to cover your changes
- In your PR you change
else
to anelif
, could you add anotherelse
so that in case none of the conditions are met, it will raise an exception or return something else. Thank you