diff options
| author | Loic Bistuer <loic.bistuer@gmail.com> | 2014-07-06 13:57:23 +0700 |
|---|---|---|
| committer | Loic Bistuer <loic.bistuer@gmail.com> | 2014-07-06 15:00:03 +0700 |
| commit | a1ddfe440151c81898b94df4d5ea99696398c3f7 (patch) | |
| tree | 81081f1c7f370dd6f89f3567dee0a1c71549bf35 | |
| parent | 8fbd9b0b1cc7b1afa7b77a421423ba4ec2a80416 (diff) | |
[1.7.x] Fixed #22906 -- Added a more helpful repr to migrations' ModelState.
Thanks Collin Anderson for the report and original patch.
Backport of 2572c07cc6 from master
| -rw-r--r-- | django/db/migrations/state.py | 3 | ||||
| -rw-r--r-- | tests/migrations/test_state.py | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index 69bfbb2ab2..d27e5013b7 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -300,6 +300,9 @@ class ModelState(object): return field raise ValueError("No field called %s on model %s" % (name, self.name)) + def __repr__(self): + return "<ModelState: '%s.%s'>" % (self.app_label, self.name) + def __eq__(self, other): return ( (self.app_label == other.app_label) and diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index 45b3d363de..ebeaffb787 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -420,3 +420,13 @@ class ModelStateTests(TestCase): state = ModelState('app', 'Model', [('name', field)]) Model = state.render(apps) self.assertNotEqual(Model._meta.get_field('name'), field) + + def test_repr(self): + field = models.CharField(max_length=1) + state = ModelState('app', 'Model', [('name', field)], bases=['app.A', 'app.B', 'app.C']) + self.assertEqual(repr(state), "<ModelState: 'app.Model'>") + + project_state = ProjectState() + project_state.add_model_state(state) + with self.assertRaisesMessage(InvalidBasesError, "Cannot resolve bases for [<ModelState: 'app.Model'>]"): + project_state.render() |
