Skip to content

Commit 9e5b833

Browse files
authored
Update JSON path compilation for Django version 6.0
compile_json_path is no longer defined in django.db.models.fields.json in Django 6.0
1 parent 87a6fae commit 9e5b833

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mssql/functions.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
if VERSION >= (3, 1):
2525
from django.db.models.fields.json import (
2626
KeyTransform, KeyTransformIn, KeyTransformExact,
27-
HasKeyLookup, compile_json_path)
28-
27+
HasKeyLookup)
28+
if VERSION >= (3, 1) and VERSION < (6, 0):
29+
from django.db.models.fields.json import compile_json_path
30+
2931
if VERSION >= (3, 2):
3032
from django.db.models.functions.math import Random
3133

@@ -327,7 +329,10 @@ def _combine_conditions(conditions):
327329
if isinstance(self.lhs, KeyTransform):
328330
# If lhs is a KeyTransform, preprocess to get SQL and JSON path
329331
lhs, _, lhs_key_transforms = self.lhs.preprocess_lhs(compiler, connection)
330-
lhs_json_path = compile_json_path(lhs_key_transforms)
332+
if VERSION >= (6, 0):
333+
lhs_json_path = connection.ops.compile_json_path(lhs_key_transforms)
334+
else:
335+
lhs_json_path = compile_json_path(lhs_key_transforms)
331336
lhs_params = []
332337
else:
333338
# Otherwise, process lhs normally and set default JSON path
@@ -355,7 +360,10 @@ def _combine_conditions(conditions):
355360
if VERSION >= (4, 1):
356361
# For Django 4.1+, split out the final key and build the JSON path accordingly
357362
*rhs_key_transforms, final_key = rhs_key_transforms
358-
rhs_json_path = compile_json_path(rhs_key_transforms, include_root=False)
363+
if VERSION >= (6, 0):
364+
rhs_json_path = connection.ops.compile_json_path(rhs_key_transforms, include_root=False)
365+
else:
366+
rhs_json_path = compile_json_path(rhs_key_transforms, include_root=False)
359367
rhs_json_path += self.compile_json_path_final_key(final_key)
360368
rhs_params.append(lhs_json_path + rhs_json_path)
361369
else:

0 commit comments

Comments
 (0)