Opened 4 years ago
Last modified 4 years ago
#32350 closed Bug
Showmigrations applied timestamp can cause runtime error — at Version 1
Reported by: | Daniel Ebrahimian | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | management command showmigrations applied timestamp |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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)