[Django] #32182: Nested KeyTransform errors when used with a subquery

11 views
Skip to first unread message

Django

unread,
Nov 9, 2020, 1:53:52 PM11/9/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery
-------------------------------------+-------------------------------------
Reporter: Hannes | Owner: Hannes Ljungberg
Ljungberg |
Type: Bug | Status: assigned
Component: Database | Version: 3.1
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 |
-------------------------------------+-------------------------------------
Annotating a subquery which returns a JSONField and then applying a nested
KeyTransform on that annotation results in a `TypeError`.

Example:

{{{
NullableJSONModel.objects.annotate(
subquery_value=models.Subquery(
NullableJSONModel.objects.filter(id=OuterRef("id")).values("value")[:1]
),
expr=KeyTransform("foo", KeyTransform("bar", "subquery_value")),
)
}}}

{{{
Traceback (most recent call last):
File "/tests/django/tests/model_fields/test_jsonfield.py", line 421, in
test_nested_key_transform_on_subquery
[self.objs[4]],
File "/usr/local/lib/python3.6/unittest/case.py", line 1005, in
assertSequenceEqual
difflib.ndiff(pprint.pformat(seq1).splitlines(),
File "/usr/local/lib/python3.6/pprint.py", line 58, in pformat
compact=compact).pformat(object)
File "/usr/local/lib/python3.6/pprint.py", line 144, in pformat
self._format(object, sio, 0, 0, {}, 0)
File "/usr/local/lib/python3.6/pprint.py", line 161, in _format
rep = self._repr(object, context, level)
File "/usr/local/lib/python3.6/pprint.py", line 393, in _repr
self._depth, level)
File "/usr/local/lib/python3.6/pprint.py", line 405, in format
return _safe_repr(object, context, maxlevels, level)
File "/usr/local/lib/python3.6/pprint.py", line 555, in _safe_repr
rep = repr(object)
File "/tests/django/django/db/models/query.py", line 256, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/tests/django/django/db/models/query.py", line 280, in __iter__
self._fetch_all()
File "/tests/django/django/db/models/query.py", line 1320, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/tests/django/django/db/models/query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch,
chunk_size=self.chunk_size)
File "/tests/django/django/db/models/sql/compiler.py", line 1147, in
execute_sql
sql, params = self.as_sql()
File "/tests/django/django/db/models/sql/compiler.py", line 498, in
as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/tests/django/django/db/models/sql/compiler.py", line 55, in
pre_sql_setup
self.setup_query()
File "/tests/django/django/db/models/sql/compiler.py", line 46, in
setup_query
self.select, self.klass_info, self.annotation_col_map =
self.get_select()
File "/tests/django/django/db/models/sql/compiler.py", line 262, in
get_select
sql, params = self.compile(col)
File "/tests/django/django/db/models/sql/compiler.py", line 428, in
compile
sql, params = vendor_impl(self, self.connection)
File "/tests/django/django/db/models/fields/json.py", line 305, in
as_postgresql
return '(%s %s %%s)' % (lhs, self.postgres_nested_operator), params +
[key_transforms,]
TypeError: can only concatenate tuple (not "list") to tuple
}}}

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

Django

unread,
Nov 9, 2020, 1:58:10 PM11/9/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes

| Ljungberg
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/13657

--
Ticket URL: <https://code.djangoproject.com/ticket/32182#comment:1>

Django

unread,
Nov 9, 2020, 2:27:17 PM11/9/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery on PostgreSQL.

-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

It's not a regression, but a bug in a new feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/32182#comment:2>

Django

unread,
Nov 10, 2020, 1:11:31 AM11/10/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


Comment:

#30704

--
Ticket URL: <https://code.djangoproject.com/ticket/32182#comment:3>

Django

unread,
Nov 10, 2020, 2:13:15 AM11/10/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0773837e15bb632afffb6848a58c59a791008fa1" 0773837]:
{{{
#!CommitTicketReference repository=""
revision="0773837e15bb632afffb6848a58c59a791008fa1"
Fixed #32182 -- Fixed crash of JSONField nested key transforms with
subquery annotations on PostgreSQL.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32182#comment:4>

Django

unread,
Nov 10, 2020, 2:13:41 AM11/10/20
to django-...@googlegroups.com
#32182: Nested KeyTransform errors when used with a subquery on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"cc3870c30f0338a09e440430d5dcc028d23f1a02" cc3870c3]:
{{{
#!CommitTicketReference repository=""
revision="cc3870c30f0338a09e440430d5dcc028d23f1a02"
[3.1.x] Fixed #32182 -- Fixed crash of JSONField nested key transforms


with subquery annotations on PostgreSQL.

Backport of 0773837e15bb632afffb6848a58c59a791008fa1 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32182#comment:5>

Reply all
Reply to author
Forward
0 new messages