From f951bb78cbf179f0fb70fe74ae0c218925fd7ede Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 28 Apr 2016 18:20:48 -0400 Subject: [PATCH] Refs #26521 -- Adjusted CreateModel bases validation to account for mixins. Thanks Collin for the report. --- django/db/migrations/operations/models.py | 11 +++++------ tests/migrations/test_operations.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 5fa9addb12..10af84cc47 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -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() - for base in self.bases - if base is not models.Model) - ) + _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 + )) _check_for_duplicates('managers', (name for name, _ in self.managers)) def deconstruct(self): diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index d34a6a4284..f86a39f5ee 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -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 in CreateModel bases argument." + with self.assertRaisesMessage(ValueError, message): + migrations.CreateModel( + "Pony", + fields=[], + bases=(models.Model, models.Model,), + ) + message = "Found duplicate value 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.'):