Re: [Django] #36494: Various failures in JSONField lookups when using expressions in right-hand side

4 views
Skip to first unread message

Django

unread,
Oct 8, 2025, 10:20:54 AM10/8/25
to django-...@googlegroups.com
#36494: Various failures in JSONField lookups when using expressions in right-hand
side
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* owner: (none) => Jacob Walls
* status: new => assigned

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

Django

unread,
Oct 8, 2025, 10:22:57 AM10/8/25
to django-...@googlegroups.com
#36494: Various failures in JSONField lookups when using expressions in right-hand
side
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
Type: | Walls
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | 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 Natalia Bidart):

* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization

Comment:

Thank you for the extra details, accepting on the basis to "invite PRs per
lookup to either raise a better exception or add support if the effort is
not massive".
--
Ticket URL: <https://code.djangoproject.com/ticket/36494#comment:4>

Django

unread,
Feb 14, 2026, 2:36:07 AMFeb 14
to django-...@googlegroups.com
#36494: Various failures in JSONField lookups when using expressions in right-hand
side
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
Type: | Walls
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | 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 VIZZARD-X):

* cc: VIZZARD-X (added)
* has_patch: 0 => 1

Comment:

PR https://github.com/django/django/pull/20702
--
Ticket URL: <https://code.djangoproject.com/ticket/36494#comment:5>

Django

unread,
Mar 8, 2026, 8:56:13 AM (10 days ago) Mar 8
to django-...@googlegroups.com
#36494: Various failures in JSONField lookups when using expressions in right-hand
side
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
Type: | Walls
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* needs_better_patch: 0 => 1

Comment:

There's a PostgreSQL failure to look at:
{{{#!python
======================================================================
ERROR: test_numeric_lookup_with_expression
(model_fields.test_jsonfield.TestQuerying.test_numeric_lookup_with_expression)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/clifford/code/django/django/db/backends/utils.py", line 105,
in _execute
return self.cursor.execute(sql, params)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/home/clifford/.pyenv/versions/dj/lib/python3.14/site-
packages/psycopg/cursor.py", line 117, in execute
raise ex.with_traceback(None)
psycopg.errors.UndefinedFunction: operator does not exist: jsonb > integer
LINE 1: ...("model_fields_nullablejsonmodel"."value" -> 'c') > 999 LIMI...
^
HINT: No operator matches the given name and argument types. You might
need to add explicit type casts.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/clifford/code/django/tests/model_fields/test_jsonfield.py",
line 1299, in test_numeric_lookup_with_expression
self.assertIs(qs_val.exists(), False)
~~~~~~~~~~~~~^^
File "/home/clifford/code/django/django/db/models/query.py", line 1409,
in exists
return self.query.has_results(using=self.db)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/home/clifford/code/django/django/db/models/sql/query.py", line
681, in has_results
return compiler.has_results()
~~~~~~~~~~~~~~~~~~~~^^
File "/home/clifford/code/django/django/db/models/sql/compiler.py", line
1599, in has_results
return bool(self.execute_sql(SINGLE))
~~~~~~~~~~~~~~~~^^^^^^^^
File "/home/clifford/code/django/django/db/models/sql/compiler.py", line
1631, in execute_sql
cursor.execute(sql, params)
~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/home/clifford/code/django/django/db/backends/utils.py", line 79,
in execute
return self._execute_with_wrappers(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
sql, params, many=False, executor=self._execute
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/home/clifford/code/django/django/db/backends/utils.py", line 92,
in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/clifford/code/django/django/db/backends/utils.py", line 100,
in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/clifford/code/django/django/db/utils.py", line 94, in
__exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/clifford/code/django/django/db/backends/utils.py", line 105,
in _execute
return self.cursor.execute(sql, params)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/home/clifford/.pyenv/versions/dj/lib/python3.14/site-
packages/psycopg/cursor.py", line 117, in execute
raise ex.with_traceback(None)
django.db.utils.ProgrammingError: operator does not exist: jsonb > integer
LINE 1: ...("model_fields_nullablejsonmodel"."value" -> 'c') > 999 LIMI...
^
HINT: No operator matches the given name and argument types. You might
need to add explicit type casts.

----------------------------------------------------------------------
Ran 81 tests in 0.768s

FAILED (errors=1, skipped=4)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36494#comment:6>

Django

unread,
9:13 AM (7 hours ago) 9:13 AM
to django-...@googlegroups.com
#36494: Various failures in JSONField lookups when using expressions in right-hand
side
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
Type: | Walls
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | 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 VIZZARD-X):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36494#comment:7>
Reply all
Reply to author
Forward
0 new messages