Re: [Django] #31956: QuerySet.order_by() chained with values() crashes on JSONField with a custom decoder on PostgreSQL. (was: JSONField doesn't support ORDER BY clauses after aggregation)

6 views
Skip to first unread message

Django

unread,
Aug 28, 2020, 1:04:53 AM8/28/20
to django-...@googlegroups.com
#31956: QuerySet.order_by() chained with values() crashes on JSONField with a
custom decoder on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Marc DEBUREAUX | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => assigned
* severity: Normal => Release blocker
* cc: sage, Simon Charette (added)
* owner: nobody => felixxm
* stage: Unreviewed => Accepted


Comment:

Thanks for this ticket. I was able to reproduce the crash on PostgreSQL
with a `JSONField` with a custom decoder. It's caused by
[https://github.com/django/django/blob/e39e727ded673e74016b5d3658d23cbe20234d11/django/db/models/fields/json.py#L94-L100
the different format] used in this case. Can you confirm that the
following patch fix this issue for you?
{{{
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
index a9768919a2..af0419356a 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -1211,6 +1211,7 @@ class OrderBy(BaseExpression):
template = '%%(expression)s IS NOT NULL, %s' % template
connection.ops.check_expression_support(self)
expression_sql, params = compiler.compile(self.expression)
+ expression_sql, params = self.expression.select_format(compiler,
expression_sql, params)
placeholders = {
'expression': expression_sql,
'ordering': 'DESC' if self.descending else 'ASC',
}}}

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

Reply all
Reply to author
Forward
0 new messages