From 01104368ff77c788f95377e8aceb48772a42fb42 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 24 Sep 2019 10:32:26 +0200 Subject: [PATCH] Refs #29444 -- Removed redundant DatabaseFeatures.can_return_multiple_columns_from_insert. Unnecessary since b31e63879eb5d9717e9f890401f7222e4f00c910. --- django/db/backends/base/features.py | 1 - django/db/backends/oracle/features.py | 1 - django/db/backends/postgresql/features.py | 1 - django/db/models/sql/compiler.py | 8 -------- tests/queries/test_db_returning.py | 19 +++---------------- 5 files changed, 3 insertions(+), 27 deletions(-) diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 89b417c7de..4058b10a5e 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -23,7 +23,6 @@ class BaseDatabaseFeatures: can_use_chunked_reads = True can_return_columns_from_insert = False - can_return_multiple_columns_from_insert = False can_return_rows_from_bulk_insert = False has_bulk_insert = True uses_savepoints = True diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index 4b3d26d74b..73a6e86686 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -10,7 +10,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): has_select_for_update_of = True select_for_update_of_column = True can_return_columns_from_insert = True - can_return_multiple_columns_from_insert = True can_introspect_autofield = True supports_subqueries_in_group_by = False supports_transactions = True diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py index 866a0f98e7..907ba136fb 100644 --- a/django/db/backends/postgresql/features.py +++ b/django/db/backends/postgresql/features.py @@ -8,7 +8,6 @@ from django.utils.functional import cached_property class DatabaseFeatures(BaseDatabaseFeatures): allows_group_by_selected_pks = True can_return_columns_from_insert = True - can_return_multiple_columns_from_insert = True can_return_rows_from_bulk_insert = True has_real_datatype = True has_native_uuid_field = True diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 22cd09c30c..85adbfdcd9 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1334,14 +1334,6 @@ class SQLInsertCompiler(SQLCompiler): if self.connection.features.can_return_rows_from_bulk_insert and len(self.query.objs) > 1: return self.connection.ops.fetch_returned_insert_rows(cursor) if self.connection.features.can_return_columns_from_insert: - if ( - len(self.returning_fields) > 1 and - not self.connection.features.can_return_multiple_columns_from_insert - ): - raise NotSupportedError( - 'Returning multiple columns from INSERT statements is ' - 'not supported on this database backend.' - ) assert len(self.query.objs) == 1 return self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params) return [self.connection.ops.last_insert_id( diff --git a/tests/queries/test_db_returning.py b/tests/queries/test_db_returning.py index af9d041393..9ba352a7ab 100644 --- a/tests/queries/test_db_returning.py +++ b/tests/queries/test_db_returning.py @@ -1,7 +1,7 @@ import datetime -from django.db import NotSupportedError, connection -from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature +from django.db import connection +from django.test import TestCase, skipUnlessDBFeature from django.test.utils import CaptureQueriesContext from .models import DumbCategory, NonIntegerPKReturningModel, ReturningModel @@ -25,7 +25,6 @@ class ReturningValuesTests(TestCase): self.assertTrue(obj.created) self.assertIsInstance(obj.created, datetime.datetime) - @skipUnlessDBFeature('can_return_multiple_columns_from_insert') def test_insert_returning_multiple(self): with CaptureQueriesContext(connection) as captured_queries: obj = ReturningModel.objects.create() @@ -42,19 +41,7 @@ class ReturningValuesTests(TestCase): self.assertTrue(obj.pk) self.assertIsInstance(obj.created, datetime.datetime) - @skipIfDBFeature('can_return_multiple_columns_from_insert') - def test_insert_returning_multiple_not_supported(self): - msg = ( - 'Returning multiple columns from INSERT statements is ' - 'not supported on this database backend.' - ) - with self.assertRaisesMessage(NotSupportedError, msg): - ReturningModel.objects.create() - - @skipUnlessDBFeature( - 'can_return_rows_from_bulk_insert', - 'can_return_multiple_columns_from_insert', - ) + @skipUnlessDBFeature('can_return_rows_from_bulk_insert') def test_bulk_insert(self): objs = [ReturningModel(), ReturningModel(pk=2 ** 11), ReturningModel()] ReturningModel.objects.bulk_create(objs)