#32350: Showmigrations applied timestamp can cause runtime error
-------------------------------------+-------------------------------------
               Reporter:  Daniel     |          Owner:  nobody
  Ebrahimian                         |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  3.1
  (Management commands)              |       Keywords:  management command
               Severity:  Normal     |  showmigrations applied timestamp
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32350>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.47a0afb987ec0cd28e400ddbe76f8476%40djangoproject.com.

Reply via email to