diff options
| author | Daniel Ebrahimian <git@danielebra.com> | 2021-01-14 11:08:27 +1100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-04 21:17:26 +0100 |
| commit | 3f8979e37b6c498101d09a583ccc521d7f2879e5 (patch) | |
| tree | 21e8da5ed2fac791f6e6bc4bdcb5bdc6013d0dc3 | |
| parent | e48e78738e224a056df57b7cb08bd48ac0e54f60 (diff) | |
Fixed #32350 -- Fixed showmigrations crash for applied squashed migrations.
Thanks Simon Charette for reviews.
| -rw-r--r-- | django/core/management/commands/showmigrations.py | 2 | ||||
| -rw-r--r-- | tests/migrations/test_commands.py | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/django/core/management/commands/showmigrations.py b/django/core/management/commands/showmigrations.py index 48bea1f3f0..e62a1b8593 100644 --- a/django/core/management/commands/showmigrations.py +++ b/django/core/management/commands/showmigrations.py @@ -92,7 +92,7 @@ class Command(BaseCommand): # Mark it as applied/unapplied if applied_migration: output = ' [X] %s' % title - if self.verbosity >= 2: + if self.verbosity >= 2 and hasattr(applied_migration, 'applied'): output += ' (applied at %s)' % applied_migration.applied.strftime('%Y-%m-%d %H:%M:%S') self.stdout.write(output) else: diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 2477872423..9346ba63e9 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -335,6 +335,44 @@ class MigrateTests(MigrationTestBase): # Cleanup by unmigrating everything call_command("migrate", "migrations", "zero", verbosity=0) + @override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations_squashed'}) + def test_showmigrations_list_squashed(self): + out = io.StringIO() + call_command('showmigrations', format='list', stdout=out, verbosity=2, no_color=True) + self.assertEqual( + 'migrations\n' + ' [ ] 0001_squashed_0002 (2 squashed migrations)\n', + out.getvalue().lower(), + ) + out = io.StringIO() + call_command( + 'migrate', + 'migrations', + '0001_squashed_0002', + stdout=out, + verbosity=2, + no_color=True, + ) + try: + self.assertIn( + 'operations to perform:\n' + ' target specific migration: 0001_squashed_0002, from migrations\n' + 'running pre-migrate handlers for application migrations\n' + 'running migrations:\n' + ' applying migrations.0001_squashed_0002... ok (', + out.getvalue().lower(), + ) + out = io.StringIO() + call_command('showmigrations', format='list', stdout=out, verbosity=2, no_color=True) + self.assertEqual( + 'migrations\n' + ' [x] 0001_squashed_0002 (2 squashed migrations)\n', + out.getvalue().lower(), + ) + finally: + # Unmigrate everything. + call_command('migrate', 'migrations', 'zero', verbosity=0) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_run_before"}) def test_showmigrations_plan(self): """ |
