Opened 8 years ago
Closed 3 years ago
#27694 closed Cleanup/optimization (fixed)
Improve documentation of supported lookups on HStore & JSON fields
Reported by: | Stephen Burrows | Owned by: | Sarah Abderemane |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The documentation of supported lookups on HStore & JSON fields is lacking. For example, HStoreField supports iexact
lookups, but the documentation has a scary warning implying that this is not the case:
Since any string could be a key in a hstore value, any lookup other than those listed below will be interpreted as a key lookup.
iexact is not listed below – but neither is contains, which is used directly above the scary warning as an example of how "You can chain other lookups after key lookups". (Actually, contains is listed below, but it's a different contains that applies only to the field level and not to a specific key.)
I suspect that the intended meaning is that all lookups are supported after a key lookup, and that the first lookup on the hstore field must be a key or one of the special lookups listed below.
JSONField does not mention being able to chain lookups after key lookups at all - but I can see people using gt and in in blog posts like this. BUT iexact lookups don't currently work on JSONField.
Change History (17)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → Cleanup/optimization |
comment:2 by , 5 years ago
comment:4 by , 4 years ago
Easy pickings: | set |
---|
comment:6 by , 3 years ago
Has patch: | unset |
---|---|
Owner: | removed |
Status: | assigned → new |
Jacob, this patch has nothing to do with the HStore
docs.
comment:7 by , 3 years ago
Yeh. Not sure what that PR has to do with this ticket. Seems completely unrelated to me.
comment:8 by , 3 years ago
Thanks, I've asked the author of the unrelated patch to update the ticket number he referenced. Sorry for the noise (and for not reading the patch before linking here).
follow-up: 10 comment:9 by , 3 years ago
I'd be happy to help on this issue but HStore is new for me, iexact
on HStoreField lookup, it's based on which SQL operator ?
Same as contains @>
but it's with case-insensitive or another one ?
comment:10 by , 3 years ago
Replying to Sarah Abderemane:
I'd be happy to help on this issue but HStore is new for me,
iexact
on HStoreField lookup, it's based on which SQL operator ?
Same as contains@>
but it's with case-insensitive or another one ?
iexact
and other text-lookups should work on key transforms on HStoreField
because it returns TextField
. Maybe it's enough to add a similar note to the one about JSONField
, e.g.:
.. note:: Key transforms can also be chained with: :lookup:`contains`, :lookup:`icontains`, :lookup:`endswith`, :lookup:`iendswith`, :lookup:`iexact`, :lookup:`regex`, :lookup:`iregex`, :lookup:`startswith`, and :lookup:`istartswith`.
This is untested so some tests will also be required.
comment:11 by , 3 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Thanks Mariusz, I'll try to see for that
comment:17 by , 3 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
JSONField
-part of this ticket is fixed as a part of PR.