#27205: Django Postgres ArrayField __contain lookup does not behave expectedly
-------------------------------------+-------------------------------------
     Reporter:  Dean-Christian-      |                    Owner:  nobody
  Armada                             |
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgresql,          |             Triage Stage:
  arrayfield                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by charettes):

 > I guess may be similar to #26511.

 It's the same underlying issue as #26511.

 What we'd need here is a way to express we want the text value of a key
 (using the `->>` operator instead of `->`). Ideally the `__contains`
 lookup wouldn't be overloaded for containment (`@>`) for the `JSONField`
 and we'd define a special lookup that takes care of using the correct
 operator but it's too late now.

 #26511 suggests introducing a
 [https://github.com/django/django/compare/master...charettes:jsonb-fts
 #diff-57ceaae67721b3f8d5729222c032af8eR88 transform] to deal with this
 issue but at this point I can't think of a way to expose it as a lookup
 (e.g `data__breed__text__contains='collie'`) since these fields are
 completely unstructured and could include a key conflicting with the
 chosen lookup name (e.g. `{'data': {'breed': {'text': 'terrier'}}}`).

 If we were to introduce this transform the reported queryset could be
 rewritten as:

 {{{#!python
 Dog.objects.annotate(breed=KeyTextTransform('breed',
 'data')).filter(breed__contains='l')
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27205#comment:2>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/079.5f03a4670ea3495c9d5b1d2348131210%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to