Refs #26521 -- Adjusted CreateModel bases validation to account for mixins.
Thanks Collin for the report.
This commit is contained in:
parent
ce32c3e2cc
commit
f951bb78cb
|
@ -56,12 +56,11 @@ class CreateModel(ModelOperation):
|
|||
# Sanity-check that there are no duplicated field names, bases, or
|
||||
# manager names
|
||||
_check_for_duplicates('fields', (name for name, _ in self.fields))
|
||||
_check_for_duplicates(
|
||||
'bases',
|
||||
(base._meta.label_lower if isinstance(base, models.base.ModelBase) else base.lower()
|
||||
_check_for_duplicates('bases', (
|
||||
base._meta.label_lower if hasattr(base, '_meta') else
|
||||
base.lower() if isinstance(base, six.string_types) else base
|
||||
for base in self.bases
|
||||
if base is not models.Model)
|
||||
)
|
||||
))
|
||||
_check_for_duplicates('managers', (name for name, _ in self.managers))
|
||||
|
||||
def deconstruct(self):
|
||||
|
|
|
@ -19,6 +19,10 @@ except ImportError:
|
|||
sqlparse = None
|
||||
|
||||
|
||||
class Mixin(object):
|
||||
pass
|
||||
|
||||
|
||||
class OperationTestBase(MigrationTestBase):
|
||||
"""
|
||||
Common functions to help test operations.
|
||||
|
@ -244,6 +248,20 @@ class OperationTests(OperationTestBase):
|
|||
fields=[],
|
||||
bases=(UnicodeModel, 'migrations.UnicodeModel',),
|
||||
)
|
||||
message = "Found duplicate value <class 'django.db.models.base.Model'> in CreateModel bases argument."
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=(models.Model, models.Model,),
|
||||
)
|
||||
message = "Found duplicate value <class 'migrations.test_operations.Mixin'> in CreateModel bases argument."
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=(Mixin, Mixin,),
|
||||
)
|
||||
|
||||
def test_create_model_with_duplicate_manager_name(self):
|
||||
with self.assertRaisesMessage(ValueError, 'Found duplicate value objects in CreateModel managers argument.'):
|
||||
|
|
Loading…
Reference in New Issue