Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Optimizer throws an exception for union queries #139

Open
eloff opened this issue Nov 1, 2022 · 1 comment
Open

Optimizer throws an exception for union queries #139

eloff opened this issue Nov 1, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@eloff
Copy link
Contributor

eloff commented Nov 1, 2022

You should be able to detect that it's a union query and use prefetch_related instead of select_related.

File "/app/.heroku/python/lib/python3.10/site-packages/strawberry_django_plus/type.py", line 318, in <lambda>
     lambda *args, **kwargs: resolve_connection(
File "/app/.heroku/python/lib/python3.10/site-packages/strawberry_django_plus/utils/resolvers.py", line 533, in resolve_connection
     nodes = ext.optimize(nodes, info=info)
File "/app/.heroku/python/lib/python3.10/site-packages/strawberry_django_plus/optimizer.py", line 639, in optimize
    return optimize(qs, info, config=config, store=store)
File "/app/.heroku/python/lib/python3.10/site-packages/strawberry_django_plus/optimizer.py", line 375, in optimize
     qs = store.apply(qs, info=info, config=config)
File "/app/.heroku/python/lib/python3.10/site-packages/strawberry_django_plus/optimizer.py", line 530, in apply
    qs = qs.select_related(*self.select_related)
File "/app/.heroku/python/lib/python3.10/site-packages/django/db/models/query.py", line 1049, in select_related
    self._not_support_combined_queries('select_related')
File "/app/.heroku/python/lib/python3.10/site-packages/django/db/models/query.py", line 1398, in _not_support_combined_queries
    raise NotSupportedError(

django.db.utils.NotSupportedError: Calling QuerySet.select_related() after union() is not supported.
@bellini666
Copy link
Member

Hey @eloff ,

Very interesting corner case. Would you like to try to open a PR to fix this? Otherwise I'll try to take a look at it next week

@bellini666 bellini666 added the bug Something isn't working label Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants