#30103: Allow Q objects to be hashable, so that they can be used in sets
-------------------------------------+-------------------------------------
               Reporter:  Keryn      |          Owner:  nobody
  Knight                             |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Given:
 {{{
 >>> x = set()
 >>> x.add(Q(a=1))
 >>> x.add(Q(a=1))
 }}}
 I was *expecting* that the `x` would end up with `{<Q: (AND: ('a', 1))>}`
 but instead it ends up with `{<Q: (AND: ('a', 1))>, <Q: (AND: ('a', 1))>}`

 For Q objects to work in sets (and as dictionary keys I guess) the class
 would need to implement `__hash__` and `__eq__` methods I think. This is
 slightly complicated by the fact it consumes all `*args, **kwargs` so
 doesn't necessarily have a concrete set of values to easily equality-check
 (and they could feasibly be nested, and in a different order [eg: `Q(a=1,
 b=2)` and `Q(b=2, a=1)`)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30103>
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/052.a85b0c00c7afa54ee3de29341754e9d8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to