Refs #29444 -- Removed redundant DatabaseFeatures.can_return_multiple_columns_from_insert.

Unnecessary since b31e63879e.
This commit is contained in:
Mariusz Felisiak 2019-09-24 10:32:26 +02:00
parent b31e63879e
commit 01104368ff
5 changed files with 3 additions and 27 deletions

View File

@ -23,7 +23,6 @@ class BaseDatabaseFeatures:
can_use_chunked_reads = True can_use_chunked_reads = True
can_return_columns_from_insert = False can_return_columns_from_insert = False
can_return_multiple_columns_from_insert = False
can_return_rows_from_bulk_insert = False can_return_rows_from_bulk_insert = False
has_bulk_insert = True has_bulk_insert = True
uses_savepoints = True uses_savepoints = True

View File

@ -10,7 +10,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
has_select_for_update_of = True has_select_for_update_of = True
select_for_update_of_column = True select_for_update_of_column = True
can_return_columns_from_insert = True can_return_columns_from_insert = True
can_return_multiple_columns_from_insert = True
can_introspect_autofield = True can_introspect_autofield = True
supports_subqueries_in_group_by = False supports_subqueries_in_group_by = False
supports_transactions = True supports_transactions = True

View File

@ -8,7 +8,6 @@ from django.utils.functional import cached_property
class DatabaseFeatures(BaseDatabaseFeatures): class DatabaseFeatures(BaseDatabaseFeatures):
allows_group_by_selected_pks = True allows_group_by_selected_pks = True
can_return_columns_from_insert = True can_return_columns_from_insert = True
can_return_multiple_columns_from_insert = True
can_return_rows_from_bulk_insert = True can_return_rows_from_bulk_insert = True
has_real_datatype = True has_real_datatype = True
has_native_uuid_field = True has_native_uuid_field = True

View File

@ -1334,14 +1334,6 @@ class SQLInsertCompiler(SQLCompiler):
if self.connection.features.can_return_rows_from_bulk_insert and len(self.query.objs) > 1: 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) return self.connection.ops.fetch_returned_insert_rows(cursor)
if self.connection.features.can_return_columns_from_insert: 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 assert len(self.query.objs) == 1
return self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params) return self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params)
return [self.connection.ops.last_insert_id( return [self.connection.ops.last_insert_id(

View File

@ -1,7 +1,7 @@
import datetime import datetime
from django.db import NotSupportedError, connection from django.db import connection
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import CaptureQueriesContext from django.test.utils import CaptureQueriesContext
from .models import DumbCategory, NonIntegerPKReturningModel, ReturningModel from .models import DumbCategory, NonIntegerPKReturningModel, ReturningModel
@ -25,7 +25,6 @@ class ReturningValuesTests(TestCase):
self.assertTrue(obj.created) self.assertTrue(obj.created)
self.assertIsInstance(obj.created, datetime.datetime) self.assertIsInstance(obj.created, datetime.datetime)
@skipUnlessDBFeature('can_return_multiple_columns_from_insert')
def test_insert_returning_multiple(self): def test_insert_returning_multiple(self):
with CaptureQueriesContext(connection) as captured_queries: with CaptureQueriesContext(connection) as captured_queries:
obj = ReturningModel.objects.create() obj = ReturningModel.objects.create()
@ -42,19 +41,7 @@ class ReturningValuesTests(TestCase):
self.assertTrue(obj.pk) self.assertTrue(obj.pk)
self.assertIsInstance(obj.created, datetime.datetime) self.assertIsInstance(obj.created, datetime.datetime)
@skipIfDBFeature('can_return_multiple_columns_from_insert') @skipUnlessDBFeature('can_return_rows_from_bulk_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',
)
def test_bulk_insert(self): def test_bulk_insert(self):
objs = [ReturningModel(), ReturningModel(pk=2 ** 11), ReturningModel()] objs = [ReturningModel(), ReturningModel(pk=2 ** 11), ReturningModel()]
ReturningModel.objects.bulk_create(objs) ReturningModel.objects.bulk_create(objs)