mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.7.x] Fix __latest__ to actually resolve to the latest migration
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
							
								
								
									
										13
									
								
								tests/migrations/test_migrations_latest/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								tests/migrations/test_migrations_latest/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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 = [] | ||||
							
								
								
									
										0
									
								
								tests/migrations/test_migrations_latest/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/migrations/test_migrations_latest/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| from __future__ import unicode_literals | ||||
|  | ||||
| from django.db import migrations | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [] | ||||
|  | ||||
|     operations = [] | ||||
							
								
								
									
										13
									
								
								tests/migrations/test_migrations_latest_basic/0002_second.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								tests/migrations/test_migrations_latest_basic/0002_second.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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 = [] | ||||
		Reference in New Issue
	
	Block a user