#28419 closed New feature (duplicate)

Support for value() usage with PostgreSQL-specific JSONFields

Reported by: daishi Owned by: nobody
Component: contrib.postgres Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is a feature request for the PostgreSQL-specific JSONField documented here:

https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/fields/#jsonfield

Following from the example starting at:

https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/fields/#key-index-and-path-lookups

It would be great if the extended field naming allowed the following to succeed:

>>> Dog.objects.values('data__breed')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/query.py", line 697, in values
    clone = self._values(*fields, **expressions)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/query.py", line 692, in _values
    clone.query.set_values(fields)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1896, in set_values
    self.add_fields(field_names, True)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1645, in add_fields
    name.split(LOOKUP_SEP), opts, alias, allow_many=allow_m2m)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1417, in setup_joins
    names, opts, allow_many, fail_on_missing=True)
  File "/Users/daishi/.virtualenvs/testdjango/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1385, in names_to_path
    " not permitted." % (names[pos + 1], name))
FieldError: Cannot resolve keyword 'breed' into field. Join on 'data' not permitted.

I would expect the result to be ['labrador', 'collie'] (or the QuerySet equivalent thereof).

Change History (1)

comment:1 Changed 16 months ago by Tim Graham

Component: Uncategorizedcontrib.postgres
Resolution: duplicate
Status: newclosed
Type: UncategorizedNew feature

Duplicate of #28168 and #24747.

Note: See TracTickets for help on using tickets.
Back to Top