From 22bce642a9d118b97cd0c5e00ec346575c729c6f Mon Sep 17 00:00:00 2001 From: John Parton Date: Thu, 5 Sep 2024 21:53:11 -0500 Subject: [PATCH] [5.1.x] Fixed #35734 -- Used JSONB_BUILD_OBJECT database function on PostgreSQL when using server-side bindings. Regression in 81ccf92f154c6d9eac3e30bac0aa67574d0ace15. Backport of f22ff4561ada77be98ca4db3ce117caca897696e from main. --- django/db/models/functions/comparison.py | 5 ++++- docs/releases/5.1.2.txt | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/db/models/functions/comparison.py b/django/db/models/functions/comparison.py index 6db81d6f46..d06f0a25a4 100644 --- a/django/db/models/functions/comparison.py +++ b/django/db/models/functions/comparison.py @@ -175,7 +175,10 @@ class JSONObject(Func): ) def as_postgresql(self, compiler, connection, **extra_context): - if not connection.features.is_postgresql_16: + if ( + not connection.features.is_postgresql_16 + or connection.features.uses_server_side_binding + ): copy = self.copy() copy.set_source_expressions( [ diff --git a/docs/releases/5.1.2.txt b/docs/releases/5.1.2.txt index 1cf3f9df09..6d2714df85 100644 --- a/docs/releases/5.1.2.txt +++ b/docs/releases/5.1.2.txt @@ -12,3 +12,6 @@ Bugfixes * Fixed a regression in Django 5.1 that caused a crash when using the PostgreSQL lookup :lookup:`trigram_similar` on output fields from ``Concat`` (:ticket:`35732`). + +* Fixed a regression in Django 5.1 that caused a crash of ``JSONObject()`` + when using server-side binding with PostgreSQL 16+ (:ticket:`35734`).