﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32350	Showmigrations applied timestamp can cause runtime error	Daniel Ebrahimian	nobody	"The functionality of `showmigrations --verbosity 2` will show the `applied` timestamps for migrations.

In certain scenarios, a timestamp isn't available and will cause a run time error of 

`AttributeError: 'Migration' object has no attribute 'applied'`.

An example of this is having `social_django` migrations in a project.

Proposed solution: Safely check for the `applied` timestamp to exist before logging it.

Current workaround: Don't use `--verbosity 2`

Logs

This shows the type for the `applied_migration`
{{{
<class 'django.db.migrations.recorder.MigrationRecorder.Migration.<locals>.Migration'>
 [X] 0045_auto_20201125_0810 (applied at 2021-01-13 23:39:40)
<class 'django.db.migrations.recorder.MigrationRecorder.Migration.<locals>.Migration'>
 [X] 0046_auto_20201218_0440 (applied at 2021-01-13 23:39:42)
sessions
<class 'django.db.migrations.recorder.MigrationRecorder.Migration.<locals>.Migration'>
 [X] 0001_initial (applied at 2021-01-13 23:40:46)
social_django
<class 'social_django.migrations.0001_initial.Migration'>
Traceback (most recent call last):
  File ""real_manage.py"", line 23, in <module>
    execute_from_command_line(sys.argv)
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py"", line 401, in execute_from_command_line
    utility.execute()
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py"", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/base.py"", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/base.py"", line 369, in execute
    output = self.handle(*args, **options)
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/commands/showmigrations.py"", line 52, in handle
    return self.show_list(connection, options['app_label'])
  File ""/usr/local/lib/python3.8/site-packages/django/core/management/commands/showmigrations.py"", line 97, in show_list
    output += ' (applied at %s)' % applied_migration.applied.strftime('%Y-%m-%d %H:%M:%S')
AttributeError: 'Migration' object has no attribute 'applied'
}}}

This is after the proposed pull request

{{{
 [X] 0045_auto_20201125_0810 (applied at 2021-01-13 23:39:40)
<class 'django.db.migrations.recorder.MigrationRecorder.Migration.<locals>.Migration'>
 [X] 0046_auto_20201218_0440 (applied at 2021-01-13 23:39:42)
sessions
<class 'django.db.migrations.recorder.MigrationRecorder.Migration.<locals>.Migration'>
 [X] 0001_initial (applied at 2021-01-13 23:40:46)
social_django
<class 'social_django.migrations.0001_initial.Migration'>
 [X] 0001_initial (2 squashed migrations)
<class 'social_django.migrations.0002_add_related_name.Migration'>
 [X] 0002_add_related_name (2 squashed migrations)
}}}

[https://github.com/django/django/pull/13890]
"	Bug	new	Core (Management commands)	3.1	Normal		management command showmigrations applied timestamp		Unreviewed	1	0	0	0	0	0
