From 09b63a7ccee85566dbe6dd476b507e8c310e8092 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 17 Jun 2014 22:12:31 -0700 Subject: [PATCH] Fix __latest__ to actually resolve to the latest migration --- django/db/migrations/loader.py | 2 +- tests/migrations/test_loader.py | 20 +++++++++++++++++++ .../test_migrations_latest/0001_initial.py | 13 ++++++++++++ .../test_migrations_latest/__init__.py | 0 .../0001_initial.py | 11 ++++++++++ .../0002_second.py | 13 ++++++++++++ .../test_migrations_latest_basic/__init__.py | 0 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/migrations/test_migrations_latest/0001_initial.py create mode 100644 tests/migrations/test_migrations_latest/__init__.py create mode 100644 tests/migrations/test_migrations_latest_basic/0001_initial.py create mode 100644 tests/migrations/test_migrations_latest_basic/0002_second.py create mode 100644 tests/migrations/test_migrations_latest_basic/__init__.py diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py index 26047b3a85..86987db02c 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -155,7 +155,7 @@ class MigrationLoader(object): if key[1] == "__first__": return list(self.graph.root_nodes(key[0]))[0] else: - return list(self.graph.root_nodes(key[0]))[-1] + return list(self.graph.leaf_nodes(key[0]))[0] except IndexError: if self.ignore_no_migrations: return None diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index 224deb7374..364faf5e00 100644 --- a/tests/migrations/test_loader.py +++ b/tests/migrations/test_loader.py @@ -122,6 +122,26 @@ class LoaderTests(TestCase): ], ) + @modify_settings(INSTALLED_APPS={'append': 'basic'}) + @override_settings(MIGRATION_MODULES={ + "migrations": "migrations.test_migrations_latest", + "basic": "migrations.test_migrations_latest_basic", + }) + def test_latest(self): + """ + Makes sure that __latest__ works correctly. + """ + # Load and test the plan + migration_loader = MigrationLoader(connection) + self.assertEqual( + migration_loader.graph.forwards_plan(("migrations", "0001_initial")), + [ + ("basic", "0001_initial"), + ("basic", "0002_second"), + ("migrations", "0001_initial"), + ], + ) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_name_match(self): "Tests prefix name matching" diff --git a/tests/migrations/test_migrations_latest/0001_initial.py b/tests/migrations/test_migrations_latest/0001_initial.py new file mode 100644 index 0000000000..e16bb2152d --- /dev/null +++ b/tests/migrations/test_migrations_latest/0001_initial.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("basic", "__latest__"), + ] + + operations = [] diff --git a/tests/migrations/test_migrations_latest/__init__.py b/tests/migrations/test_migrations_latest/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/migrations/test_migrations_latest_basic/0001_initial.py b/tests/migrations/test_migrations_latest_basic/0001_initial.py new file mode 100644 index 0000000000..4df0594154 --- /dev/null +++ b/tests/migrations/test_migrations_latest_basic/0001_initial.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [] + + operations = [] diff --git a/tests/migrations/test_migrations_latest_basic/0002_second.py b/tests/migrations/test_migrations_latest_basic/0002_second.py new file mode 100644 index 0000000000..49f5b1966c --- /dev/null +++ b/tests/migrations/test_migrations_latest_basic/0002_second.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("basic", "0001_initial"), + ] + + operations = [] diff --git a/tests/migrations/test_migrations_latest_basic/__init__.py b/tests/migrations/test_migrations_latest_basic/__init__.py new file mode 100644 index 0000000000..e69de29bb2