Skip to content

Commit 69d3024

Browse files
authored
Merge branch 'dev' into add-comments-support
2 parents 2590023 + 32d6fb3 commit 69d3024

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

mssql/introspection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
SQL_AUTOFIELD = -777555
1717
SQL_BIGAUTOFIELD = -777444
18+
SQL_SMALLAUTOFIELD = -777333
1819
SQL_TIMESTAMP_WITH_TIMEZONE = -155
1920

2021
FieldInfo = namedtuple("FieldInfo", BaseFieldInfo._fields + ("comment",))
@@ -29,6 +30,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
2930
data_types_reverse = {
3031
SQL_AUTOFIELD: 'AutoField',
3132
SQL_BIGAUTOFIELD: 'BigAutoField',
33+
SQL_SMALLAUTOFIELD: 'SmallAutoField',
3234
Database.SQL_BIGINT: 'BigIntegerField',
3335
# Database.SQL_BINARY: ,
3436
Database.SQL_BIT: 'BooleanField',
@@ -158,6 +160,8 @@ def get_table_description(self, cursor, table_name, identity_check=True):
158160
if identity_check and self._is_auto_field(cursor, table_name, column[0]):
159161
if column[1] == Database.SQL_BIGINT:
160162
column[1] = SQL_BIGAUTOFIELD
163+
elif column[1] == Database.SQL_SMALLINT:
164+
column[1] = SQL_SMALLAUTOFIELD
161165
else:
162166
column[1] = SQL_AUTOFIELD
163167
if column[1] == Database.SQL_WVARCHAR and column[3] < 4000:

mssql/operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def date_trunc_sql(self, lookup_type, sql, params, tzname=None):
178178

179179
# Python formats year with leading zeroes. This preserves that format for
180180
# compatibility with SQL Server's date since DATEPART drops the leading zeroes.
181-
CONVERT_YEAR = 'CONVERT(varchar(4), %s)' % sql
181+
CONVERT_YEAR = 'CONVERT(varchar(4), CONVERT(date, %s))' % sql
182182
CONVERT_QUARTER = 'CONVERT(varchar, 1+((DATEPART(quarter, %s)-1)*3))' % sql
183183
CONVERT_MONTH = 'CONVERT(varchar, DATEPART(month, %s))' % sql
184184
CONVERT_WEEK = "DATEADD(DAY, (DATEPART(weekday, %s) + 5) %%%% 7 * -1, %s)" % (sql, sql)

mssql/schema.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
348348
if (old_is_auto and not new_is_auto) or (not old_is_auto and new_is_auto):
349349
raise NotImplementedError("the backend doesn't support altering from %s to %s." %
350350
(old_field.get_internal_type(), new_field.get_internal_type()))
351-
351+
352352
# Drop any FK constraints, we'll remake them later
353353
fks_dropped = set()
354354
if old_field.remote_field and old_field.db_constraint and (django_version >= (4, 2) and self._field_should_be_altered(
@@ -830,11 +830,23 @@ def _delete_indexes(self, model, old_field, new_field):
830830
if old_field.column in columns:
831831
index_columns.append(columns)
832832

833+
for index in model._meta.indexes:
834+
columns = [model._meta.get_field(field).column for field in index.fields]
835+
if old_field.column in columns:
836+
index_columns.append(columns)
837+
833838
for fields in model._meta.unique_together:
834839
columns = [model._meta.get_field(field).column for field in fields]
835840
if old_field.column in columns:
836841
index_columns.append(columns)
837842
if index_columns:
843+
# remove duplicates first
844+
temp = []
845+
for columns in index_columns:
846+
if columns not in temp:
847+
temp.append(columns)
848+
index_columns = temp
849+
838850
for columns in index_columns:
839851
index_names = self._constraint_names(model, columns, index=True)
840852
for index_name in index_names:

testapp/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
'queries.test_db_returning.ReturningValuesTests.test_insert_returning',
160160
'queries.test_db_returning.ReturningValuesTests.test_insert_returning_non_integer',
161161
'backends.tests.BackendTestCase.test_queries',
162-
'introspection.tests.IntrospectionTests.test_smallautofield',
163162
'schema.tests.SchemaTests.test_inline_fk',
164163
'aggregation.tests.AggregateTestCase.test_aggregation_subquery_annotation_exists',
165164
'aggregation.tests.AggregateTestCase.test_aggregation_subquery_annotation_values_collision',
@@ -292,13 +291,17 @@
292291
'aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_aggregate_empty_condition',
293292
'aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_aggregate_ref_multiple_subquery_annotation',
294293
'aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_aggregate_ref_subquery_annotation',
295-
"aggregation.tests.AggregateAnnotationPruningTests.test_referenced_group_by_annotation_kept",
294+
'aggregation.tests.AggregateAnnotationPruningTests.test_referenced_group_by_annotation_kept',
295+
'aggregation.tests.AggregateAnnotationPruningTests.test_referenced_window_requires_wrapping',
296+
'aggregation.tests.AggregateAnnotationPruningTests.test_unused_aliased_aggregate_and_annotation_reverse_fk',
297+
'aggregation.tests.AggregateAnnotationPruningTests.test_unused_aliased_aggregate_and_annotation_reverse_fk_grouped',
296298
'aggregation.tests.AggregateTestCase.test_group_by_nested_expression_with_params',
297299
'expressions.tests.BasicExpressionsTests.test_aggregate_subquery_annotation',
298300
'queries.test_qs_combinators.QuerySetSetOperationTests.test_union_order_with_null_first_last',
299301
'queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_select_related_and_order',
300302
'expressions_window.tests.WindowFunctionTests.test_limited_filter',
301303
'schema.tests.SchemaTests.test_remove_ignored_unique_constraint_not_create_fk_index',
304+
'constraints.tests.UniqueConstraintTests.test_validate_nullable_textfield_with_isnull_true',
302305
]
303306

304307
REGEX_TESTS = [

0 commit comments

Comments
 (0)