Skip to content

Commit 6fe445a

Browse files
committed
Issue #25 -- Fix Django 3.2 startup issue
1 parent c2fbcad commit 6fe445a

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

mssql/compiler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from django.db.models.sql import compiler
1414
from django.db.transaction import TransactionManagementError
1515
from django.db.utils import NotSupportedError
16-
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform
16+
if django.VERSION >= (3, 1):
17+
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform
1718

1819
def _as_sql_agv(self, compiler, connection):
1920
return self.as_sql(compiler, connection, template='%(function)s(CONVERT(float, %(field)s))')
@@ -387,8 +388,6 @@ def _as_microsoft(self, node):
387388
as_microsoft = _as_sql_count
388389
elif isinstance(node, Greatest):
389390
as_microsoft = _as_sql_greatest
390-
if isinstance(node, json_KeyTransform):
391-
as_microsoft = _as_sql_json_keytransform
392391
elif isinstance(node, Least):
393392
as_microsoft = _as_sql_least
394393
elif isinstance(node, Length):
@@ -409,6 +408,9 @@ def _as_microsoft(self, node):
409408
as_microsoft = _as_sql_trim
410409
elif isinstance(node, Variance):
411410
as_microsoft = _as_sql_variance
411+
if django.VERSION >= (3, 1):
412+
if isinstance(node, json_KeyTransform):
413+
as_microsoft = _as_sql_json_keytransform
412414
if as_microsoft:
413415
node = node.copy()
414416
node.as_microsoft = types.MethodType(as_microsoft, node)

mssql/functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from django.db.models.functions.math import ATan2, Log, Ln, Mod, Round
88
from django.db.models.expressions import Case, Exists, OrderBy, When
99
from django.db.models.lookups import Lookup, In, Exact
10-
from django.db.models.fields.json import KeyTransform, KeyTransformExact
10+
if VERSION >= (3, 1):
11+
from django.db.models.fields.json import KeyTransform, KeyTransformExact
1112

1213
DJANGO3 = VERSION[0] >= 3
1314

@@ -120,7 +121,8 @@ def KeyTransformExact_process_rhs(self, compiler, connection):
120121

121122
ATan2.as_microsoft = sqlserver_atan2
122123
In.split_parameter_list_as_sql = split_parameter_list_as_sql
123-
KeyTransformExact.process_rhs = KeyTransformExact_process_rhs
124+
if VERSION >= (3, 1):
125+
KeyTransformExact.process_rhs = KeyTransformExact_process_rhs
124126
Ln.as_microsoft = sqlserver_ln
125127
Log.as_microsoft = sqlserver_log
126128
Mod.as_microsoft = sqlserver_mod

mssql/schema.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def _db_table_delete_constraint_sql(self, template, db_table, name):
235235
template,
236236
table=Table(db_table, self.quote_name),
237237
name=self.quote_name(name),
238+
include=''
238239
)
239240

240241
def alter_db_table(self, model, old_db_table, new_db_table):
@@ -689,7 +690,7 @@ def add_field(self, model, field):
689690
if self.connection.features.connection_persists_old_columns:
690691
self.connection.close()
691692

692-
def _create_unique_sql(self, model, columns, name=None, condition=None, deferrable=None):
693+
def _create_unique_sql(self, model, columns, name=None, condition=None, deferrable=None, include=None, opclasses=None):
693694
if (deferrable and not getattr(self.connection.features, 'supports_deferrable_unique_constraints', False)):
694695
return None
695696

@@ -713,20 +714,22 @@ def create_unique_name(*args, **kwargs):
713714
name=name,
714715
columns=columns,
715716
condition=' WHERE ' + condition,
716-
**statement_args
717+
**statement_args,
718+
include='',
717719
) if self.connection.features.supports_partial_indexes else None
718720
else:
719721
return Statement(
720722
self.sql_create_unique,
721723
table=table,
722724
name=name,
723725
columns=columns,
724-
**statement_args
726+
**statement_args,
727+
include='',
725728
)
726729

727730
def _create_index_sql(self, model, fields, *, name=None, suffix='', using='',
728731
db_tablespace=None, col_suffixes=(), sql=None, opclasses=(),
729-
condition=None):
732+
condition=None, include=None, expressions=None):
730733
"""
731734
Return the SQL statement to create the index for one or several fields.
732735
`sql` can be specified if the syntax differs from the standard (GIS
@@ -751,6 +754,7 @@ def create_index_name(*args, **kwargs):
751754
columns=self._index_columns(table, columns, col_suffixes, opclasses),
752755
extra=tablespace_sql,
753756
condition=(' WHERE ' + condition) if condition else '',
757+
include=''
754758
)
755759

756760
def create_model(self, model):

testapp/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
3737
]
3838

39+
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
40+
3941
ENABLE_REGEX_TESTS = False
4042

4143
TEST_RUNNER = "testapp.runners.ExcludedTestSuiteRunner"

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ envlist =
33
{py36,py37}-django22,
44
{py36,py37,py38}-django30,
55
{py36,py37,py38}-django31,
6+
{py36,py37,py38,py39}-django32
67

78
[testenv]
89
allowlist_externals =
@@ -17,3 +18,4 @@ deps =
1718
django22: django==2.2.*
1819
django30: django>=3.0,<3.1
1920
django31: django>=3.1,<3.2
21+
django32: django==3.2.*

0 commit comments

Comments
 (0)