From ef8540bb0cfca304b5f701e1e85918f37933d23d Mon Sep 17 00:00:00 2001 From: mShan0 <96149598+mShan0@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:58:11 -0800 Subject: [PATCH 1/4] revert can_return_rows_from_bulk_insert to False --- mssql/features.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mssql/features.py b/mssql/features.py index 8c1d7ff1..53233812 100644 --- a/mssql/features.py +++ b/mssql/features.py @@ -13,7 +13,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): can_introspect_small_integer_field = True can_return_columns_from_insert = True can_return_id_from_insert = True - can_return_rows_from_bulk_insert = True + can_return_rows_from_bulk_insert = False can_rollback_ddl = True can_use_chunked_reads = False for_update_after_from = True From 3684a02e79d403be8947f6e5a2163a483a8db575 Mon Sep 17 00:00:00 2001 From: mShan0 <96149598+mShan0@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:58:49 -0800 Subject: [PATCH 2/4] set return_rows_bulk_insert to true in testapp --- testapp/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testapp/settings.py b/testapp/settings.py index f6a19593..fa8a4e26 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -15,7 +15,7 @@ "PASSWORD": "MyPassword42", "HOST": "localhost", "PORT": "1433", - "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server", }, + "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server", "return_rows_bulk_insert": True}, }, 'other': { "ENGINE": "mssql", @@ -24,7 +24,7 @@ "PASSWORD": "MyPassword42", "HOST": "localhost", "PORT": "1433", - "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server", }, + "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server", "return_rows_bulk_insert": True}, }, } From 78f43804e833ae0a84b0614441b0475aae0c69e2 Mon Sep 17 00:00:00 2001 From: mShan0 <96149598+mShan0@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:08:36 -0800 Subject: [PATCH 3/4] move flag set in test --- testapp/tests/test_queries.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testapp/tests/test_queries.py b/testapp/tests/test_queries.py index 1f182d7d..dffa3bcd 100644 --- a/testapp/tests/test_queries.py +++ b/testapp/tests/test_queries.py @@ -7,10 +7,6 @@ class TestTableWithTrigger(TransactionTestCase): def test_insert_into_table_with_trigger(self): connection = connections['default'] - # Change can_return_rows_from_bulk_insert to be the same as when - # has_trigger = True - connection.features_class.can_return_rows_from_bulk_insert = False - with connection.schema_editor() as cursor: cursor.execute(""" CREATE TRIGGER TestTrigger @@ -21,9 +17,13 @@ def test_insert_into_table_with_trigger(self): """) try: + # Change can_return_rows_from_bulk_insert to be the same as when + # has_trigger = True + connection.features_class.can_return_rows_from_bulk_insert = False Author.objects.create(name='Foo') except django.db.utils.ProgrammingError as e: self.fail('Check for regression of issue #130. Insert with trigger failed with exception: %s' % e) finally: with connection.schema_editor() as cursor: cursor.execute("DROP TRIGGER TestTrigger") + # connection.features_class.can_return_rows_from_bulk_insert = True \ No newline at end of file From fe9cf90cdc993d9b544f5f2d47c42683273d4f44 Mon Sep 17 00:00:00 2001 From: mShan0 <96149598+mShan0@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:33:12 -0800 Subject: [PATCH 4/4] change flag back after test complete --- testapp/tests/test_queries.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testapp/tests/test_queries.py b/testapp/tests/test_queries.py index dffa3bcd..785db023 100644 --- a/testapp/tests/test_queries.py +++ b/testapp/tests/test_queries.py @@ -19,6 +19,7 @@ def test_insert_into_table_with_trigger(self): try: # Change can_return_rows_from_bulk_insert to be the same as when # has_trigger = True + old_return_rows_flag = connection.features_class.can_return_rows_from_bulk_insert connection.features_class.can_return_rows_from_bulk_insert = False Author.objects.create(name='Foo') except django.db.utils.ProgrammingError as e: @@ -26,4 +27,4 @@ def test_insert_into_table_with_trigger(self): finally: with connection.schema_editor() as cursor: cursor.execute("DROP TRIGGER TestTrigger") - # connection.features_class.can_return_rows_from_bulk_insert = True \ No newline at end of file + connection.features_class.can_return_rows_from_bulk_insert = old_return_rows_flag \ No newline at end of file