Skip to content

Commit

Permalink
Issue #25 -- Fix Django 3.2 startup issue
Browse files Browse the repository at this point in the history
  • Loading branch information
absci committed Apr 15, 2021
1 parent c2fbcad commit 6fe445a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions mssql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from django.db.models.sql import compiler
from django.db.transaction import TransactionManagementError
from django.db.utils import NotSupportedError
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform
if django.VERSION >= (3, 1):
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform

def _as_sql_agv(self, compiler, connection):
return self.as_sql(compiler, connection, template='%(function)s(CONVERT(float, %(field)s))')
Expand Down Expand Up @@ -387,8 +388,6 @@ def _as_microsoft(self, node):
as_microsoft = _as_sql_count
elif isinstance(node, Greatest):
as_microsoft = _as_sql_greatest
if isinstance(node, json_KeyTransform):
as_microsoft = _as_sql_json_keytransform
elif isinstance(node, Least):
as_microsoft = _as_sql_least
elif isinstance(node, Length):
Expand All @@ -409,6 +408,9 @@ def _as_microsoft(self, node):
as_microsoft = _as_sql_trim
elif isinstance(node, Variance):
as_microsoft = _as_sql_variance
if django.VERSION >= (3, 1):
if isinstance(node, json_KeyTransform):
as_microsoft = _as_sql_json_keytransform
if as_microsoft:
node = node.copy()
node.as_microsoft = types.MethodType(as_microsoft, node)
Expand Down
6 changes: 4 additions & 2 deletions mssql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from django.db.models.functions.math import ATan2, Log, Ln, Mod, Round
from django.db.models.expressions import Case, Exists, OrderBy, When
from django.db.models.lookups import Lookup, In, Exact
from django.db.models.fields.json import KeyTransform, KeyTransformExact
if VERSION >= (3, 1):
from django.db.models.fields.json import KeyTransform, KeyTransformExact

DJANGO3 = VERSION[0] >= 3

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

ATan2.as_microsoft = sqlserver_atan2
In.split_parameter_list_as_sql = split_parameter_list_as_sql
KeyTransformExact.process_rhs = KeyTransformExact_process_rhs
if VERSION >= (3, 1):
KeyTransformExact.process_rhs = KeyTransformExact_process_rhs
Ln.as_microsoft = sqlserver_ln
Log.as_microsoft = sqlserver_log
Mod.as_microsoft = sqlserver_mod
Expand Down
12 changes: 8 additions & 4 deletions mssql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def _db_table_delete_constraint_sql(self, template, db_table, name):
template,
table=Table(db_table, self.quote_name),
name=self.quote_name(name),
include=''
)

def alter_db_table(self, model, old_db_table, new_db_table):
Expand Down Expand Up @@ -689,7 +690,7 @@ def add_field(self, model, field):
if self.connection.features.connection_persists_old_columns:
self.connection.close()

def _create_unique_sql(self, model, columns, name=None, condition=None, deferrable=None):
def _create_unique_sql(self, model, columns, name=None, condition=None, deferrable=None, include=None, opclasses=None):
if (deferrable and not getattr(self.connection.features, 'supports_deferrable_unique_constraints', False)):
return None

Expand All @@ -713,20 +714,22 @@ def create_unique_name(*args, **kwargs):
name=name,
columns=columns,
condition=' WHERE ' + condition,
**statement_args
**statement_args,
include='',
) if self.connection.features.supports_partial_indexes else None
else:
return Statement(
self.sql_create_unique,
table=table,
name=name,
columns=columns,
**statement_args
**statement_args,
include='',
)

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

def create_model(self, model):
Expand Down
2 changes: 2 additions & 0 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
]

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

ENABLE_REGEX_TESTS = False

TEST_RUNNER = "testapp.runners.ExcludedTestSuiteRunner"
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ envlist =
{py36,py37}-django22,
{py36,py37,py38}-django30,
{py36,py37,py38}-django31,
{py36,py37,py38,py39}-django32

[testenv]
allowlist_externals =
Expand All @@ -17,3 +18,4 @@ deps =
django22: django==2.2.*
django30: django>=3.0,<3.1
django31: django>=3.1,<3.2
django32: django==3.2.*

0 comments on commit 6fe445a

Please sign in to comment.