strawberry-django-plus
strawberry-django-plus copied to clipboard
Optimization error: lookup was already seen with a different queryset. You may need to adjust the ordering of your lookups
I’m having this error (from django.db
) with my actual schema for some queries, but only if the DjangoOptimizerExtension
is in place.
I narrowed down my project to a minimum reproducible scenario.
My exact error message is:
"steps" lookup was already seen with a different queryset. You may need to adjust the ordering of your lookups
How to reproduce it ?
- Get the mini project archive: bug-prefetch-strawberry-django-plus.tar.gz
- Extract it to a folder of your choice
- Install dependencies with poetry and enter shell
- Prepare database (sqlite) and run a dev server:
./manage.py migrate
./manage.py runscript app.import
./manage.py runserver_plus
- Open your browser to
/graphql/
to openGraphiQL
and try this query:
query {
allProjects {
id
name
isPublished
workflowTemplates {
id
name
sequence
steps {
sequence
type
label
days0
daysX
}
}
}
}
- Constat the error message about prefetch clashing.
- Open
app/schema.py
file and changewith_optim = False
⇒ the bug disappear.
Site nodes
I know the optimizer is not a silver bullet and dynamically prefetching is hard. But I expect the query to complete, even if not correctly optimized.
- What I can do to my code to help the optimizer?
- How can I forsee when (and why) I need to help the optimizer (if it’s possible)?
If any information is missing, please ask. I also can be contacted directly by email at [email protected].