From 9a23470072865b7aa659e6af0b275668c85bb44d Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Wed, 17 Dec 2014 18:41:36 -0500 Subject: [PATCH] Fixed #24017 -- Added python_2_unicode_compatible in db/migrations --- django/db/migrations/graph.py | 5 +++-- django/db/migrations/migration.py | 2 ++ tests/migrations/test_graph.py | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py index 9046ec5ed1..0e3c5905d6 100644 --- a/django/db/migrations/graph.py +++ b/django/db/migrations/graph.py @@ -3,8 +3,10 @@ from collections import deque from django.db.migrations.state import ProjectState from django.utils.datastructures import OrderedSet +from django.utils.encoding import python_2_unicode_compatible +@python_2_unicode_compatible class MigrationGraph(object): """ Represents the digraph of all migrations in a project. @@ -178,6 +180,7 @@ class CircularDependencyError(Exception): pass +@python_2_unicode_compatible class NodeNotFoundError(LookupError): """ Raised when an attempt on a node is made that is not available in the graph. @@ -190,7 +193,5 @@ class NodeNotFoundError(LookupError): def __str__(self): return self.message - __unicode__ = __str__ - def __repr__(self): return "NodeNotFoundError(%r)" % self.node diff --git a/django/db/migrations/migration.py b/django/db/migrations/migration.py index 80bdb2f126..ff9d526410 100644 --- a/django/db/migrations/migration.py +++ b/django/db/migrations/migration.py @@ -1,7 +1,9 @@ from __future__ import unicode_literals from django.db.transaction import atomic +from django.utils.encoding import python_2_unicode_compatible +@python_2_unicode_compatible class Migration(object): """ The base class for all migrations. diff --git a/tests/migrations/test_graph.py b/tests/migrations/test_graph.py index c5ccdb79db..89ad206897 100644 --- a/tests/migrations/test_graph.py +++ b/tests/migrations/test_graph.py @@ -1,5 +1,6 @@ from django.test import TestCase from django.db.migrations.graph import CircularDependencyError, MigrationGraph, NodeNotFoundError +from django.utils.encoding import force_text class GraphTests(TestCase): @@ -213,7 +214,7 @@ class GraphTests(TestCase): / \ app_c: 0001<- <------------- x 0002 - And apply sqashing on app_c. + And apply squashing on app_c. """ graph = MigrationGraph() @@ -229,3 +230,18 @@ class GraphTests(TestCase): with self.assertRaises(CircularDependencyError): graph.forwards_plan(("app_c", "0001_squashed_0002")) + + def test_stringify(self): + graph = MigrationGraph() + self.assertEqual(force_text(graph), "Graph: 0 nodes, 0 edges") + + graph.add_node(("app_a", "0001"), None) + graph.add_node(("app_a", "0002"), None) + graph.add_node(("app_a", "0003"), None) + graph.add_node(("app_b", "0001"), None) + graph.add_node(("app_b", "0002"), None) + graph.add_dependency("app_a.0002", ("app_a", "0002"), ("app_a", "0001")) + graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002")) + graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002")) + + self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges")