mirror of https://github.com/django/django.git
Merge pull request #2037 from bmispelon/invalidbaseserror
Fixed TypeError when rendering ModelState with multiple bases.
This commit is contained in:
commit
a06fd092ef
|
@ -176,7 +176,7 @@ class ModelState(object):
|
||||||
for base in self.bases
|
for base in self.bases
|
||||||
)
|
)
|
||||||
if None in bases:
|
if None in bases:
|
||||||
raise InvalidBasesError("Cannot resolve one or more bases from %r" % self.bases)
|
raise InvalidBasesError("Cannot resolve one or more bases from %r" % (self.bases,))
|
||||||
# Turn fields into a dict for the body, add other bits
|
# Turn fields into a dict for the body, add other bits
|
||||||
body = dict(self.fields)
|
body = dict(self.fields)
|
||||||
body['Meta'] = meta
|
body['Meta'] = meta
|
||||||
|
|
|
@ -94,32 +94,58 @@ class StateTests(TestCase):
|
||||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
||||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
||||||
|
|
||||||
def test_render_multiple_inheritance(self):
|
def test_render_model_inheritance(self):
|
||||||
# Use a custom app cache to avoid polluting the global one.
|
|
||||||
new_app_cache = BaseAppCache()
|
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
title = models.CharField(max_length=1000)
|
title = models.CharField(max_length=1000)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = "migrations"
|
app_label = "migrations"
|
||||||
app_cache = new_app_cache
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
class Novel(Book):
|
class Novel(Book):
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = "migrations"
|
app_label = "migrations"
|
||||||
app_cache = new_app_cache
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
# First, test rendering individually
|
# First, test rendering individually
|
||||||
yet_another_app_cache = BaseAppCache()
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
# We shouldn't be able to render yet
|
# We shouldn't be able to render yet
|
||||||
with self.assertRaises(ValueError):
|
ms = ModelState.from_model(Novel)
|
||||||
ModelState.from_model(Novel).render(yet_another_app_cache)
|
with self.assertRaises(InvalidBasesError):
|
||||||
|
ms.render(app_cache)
|
||||||
|
|
||||||
# Once the parent model is in the app cache, it should be fine
|
# Once the parent model is in the app cache, it should be fine
|
||||||
ModelState.from_model(Book).render(yet_another_app_cache)
|
ModelState.from_model(Book).render(app_cache)
|
||||||
ModelState.from_model(Novel).render(yet_another_app_cache)
|
ModelState.from_model(Novel).render(app_cache)
|
||||||
|
|
||||||
|
def test_render_model_with_multiple_inheritance(self):
|
||||||
|
class Foo(models.Model):
|
||||||
|
class Meta:
|
||||||
|
app_label = "migrations"
|
||||||
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
|
class Bar(models.Model):
|
||||||
|
class Meta:
|
||||||
|
app_label = "migrations"
|
||||||
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
|
class FooBar(Foo, Bar):
|
||||||
|
class Meta:
|
||||||
|
app_label = "migrations"
|
||||||
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
|
app_cache = BaseAppCache()
|
||||||
|
|
||||||
|
# We shouldn't be able to render yet
|
||||||
|
ms = ModelState.from_model(FooBar)
|
||||||
|
with self.assertRaises(InvalidBasesError):
|
||||||
|
ms.render(app_cache)
|
||||||
|
|
||||||
|
# Once the parent models are in the app cache, it should be fine
|
||||||
|
ModelState.from_model(Foo).render(app_cache)
|
||||||
|
ModelState.from_model(Bar).render(app_cache)
|
||||||
|
ModelState.from_model(FooBar).render(app_cache)
|
||||||
|
|
||||||
def test_render_project_dependencies(self):
|
def test_render_project_dependencies(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue