strawberry-django-plus icon indicating copy to clipboard operation
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

Open cpontvieux-systra opened this issue 1 year ago • 2 comments

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 ?

./manage.py migrate
./manage.py runscript app.import
./manage.py runserver_plus
  • Open your browser to /graphql/ to open GraphiQL 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 change with_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].

cpontvieux-systra avatar Mar 02 '23 12:03 cpontvieux-systra