#28297: Same queryset result in two different queries on ORM
-------------------------------------+-------------------------------------
     Reporter:  Marcus Renno         |                    Owner:  Tom
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  join, annotation, F  |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Tom):

 I wasn't suggesting setting the hash seed value as a fix, merely as a
 debugging aide for anyone else looking at the ticket.

 I've made a MR with what I think is the correct fix:
 https://github.com/django/django/pull/8631

 The issue was that there where two joins, with differing `join_types`,
 that where considered equal in the `Join.__eq__` method, and so randomly
 one would be chosen, which was sometimes incorrect.

 Replying to [comment:12 Marcus Renno]:
 > That seems to be right, Tom. `join()` is relying on the order of the
 dictionary resulting from `.items()`.
 >
 > It's weird that setting the hash seed to 2 would solve this problem,
 though. I feel like the framework should not rely on the user changing the
 hashing seed to a static number to fix this problem, because it breaks the
 purpose (security) of the the hashing being random.
 >
 > Replying to [comment:11 Tom]:
 > > It seems to boil down to this line:
 
https://github.com/django/django/blob/stable/1.11.x/django/db/models/sql/query.py#L927
 > >
 > > The `alias_map.items()` isn't stable, with `PYTHONHASHSEED=1` then
 `reuse[0]` is `recepie_steps`, which is incorrect, but with it set to `2`
 then `reuse[0]` is (correctly) `T6`.
 > >
 > > If anyone knows how to fix this then please let me know, else I will
 try and find a suitable fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/28297#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.0d6dae8c72ccf096c09273daf846c2f7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to