From 3dc79d36a065669d7f974b6760eaa25157e21860 Mon Sep 17 00:00:00 2001 From: caramdache Date: Fri, 5 Dec 2025 14:46:51 +0100 Subject: [PATCH] Update JSON path compilation for Django 6.0 compile_json_path is no longer defined in django.db.models.fields.json in Django 6.0 --- mssql/compiler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mssql/compiler.py b/mssql/compiler.py index f59c8d40..4ff9aa0b 100644 --- a/mssql/compiler.py +++ b/mssql/compiler.py @@ -14,7 +14,9 @@ from django.db.transaction import TransactionManagementError from django.db.utils import NotSupportedError if django.VERSION >= (3, 1): - from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform + from django.db.models.fields.json import KeyTransform as json_KeyTransform +if django.VERSION >= (3, 1) and django.VERSION < (6, 0): + from django.db.models.fields.json import compile_json_path if django.VERSION >= (4, 2): from django.core.exceptions import EmptyResultSet, FullResultSet @@ -47,7 +49,7 @@ def _as_sql_greatest(self, compiler, connection): def _as_sql_json_keytransform(self, compiler, connection): lhs, params, key_transforms = self.preprocess_lhs(compiler, connection) - json_path = compile_json_path(key_transforms) + json_path = connection.ops.compile_json_path(key_transforms) return ( "COALESCE(JSON_QUERY(%s, '%s'), JSON_VALUE(%s, '%s'))" % ((lhs, json_path) * 2)