"pre_delete" signal causes issue when running migrations #11

Closed
opened 2021-07-14 23:16:21 +00:00 by ZeroHD · 1 comment
ZeroHD commented 2021-07-14 23:16:21 +00:00 (Migrated from git.canopymc.net)

It appears this signal causes issues while running migrations. The instance parameter does not allways have the file attribute.

(ve) apps@nest:~/mcm/birb$ ./manage.py migrate django_coreprotect zero                                                                                                                                                                       
Operations to perform:                                                                                                                                                                                                                       
  Unapply all migrations: django_coreprotect                                                                                                                                                                                                 
Running migrations:                                                                                                                                                                                                                          
  Rendering model states... DONE                                                                                                                                                                                                             
  Unapplying django_coreprotect.0001_initial...Traceback (most recent call last):                                                                                                                                                            
  File "./manage.py", line 21, in <module>                                                                                                                                                                                                   
    main()                                                                                                                                                                                                                                   
  File "./manage.py", line 17, in main                                                                                                                                                                                                       
    execute_from_command_line(sys.argv)                                                                                                                                                                                                      
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line                                                                                                            
    utility.execute()                                                                                                                                                                                                                        
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute                                                                                                                              
    self.fetch_command(subcommand).run_from_argv(self.argv)                                                                                                                                                                                  
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv                                                                                                                            
    self.execute(*args, **cmd_options)                                                                                                                                                                                                       
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute                                                                                                                                  
    output = self.handle(*args, **options)                                                                                                                                                                                                   
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped                                                                                                                                   
    res = handle_func(*args, **kwargs)                                                                                                                                                                                                       
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 232, in handle                                                                                                                       
    post_migrate_state = executor.migrate(                                                                                                                                                                                                   
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 121, in migrate                                                                                                                                
    state = self._migrate_all_backwards(plan, full_plan, fake=fake)                                                                                                                                                                          
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 196, in _migrate_all_backwards                                                                                                                 
    self.unapply_migration(states[migration], migration, fake=fake)                                                                                                                                                                          
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 275, in unapply_migration                                                                                                                      
    self.recorder.record_unapplied(migration.app_label, migration.name)                                                                                                                                                                      
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 88, in record_unapplied                                                                                                                        
    self.migration_qs.filter(app=app, name=name).delete()                                                                                                                                                                                    
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/models/query.py", line 711, in delete                                                                                                                                        
    deleted, _rows_count = collector.delete()                                                                                                                                                                                                
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/models/deletion.py", line 287, in delete                                                                                                                                     
    signals.pre_delete.send(                                                                                                                                                                                                                 
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 173, in send                                                                                                                                      
    return [                                                                                                                                                                                                                                 
  File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 174, in <listcomp>                                                                                                                                
    (receiver, receiver(signal=self, sender=sender, **named))                                                                                                                                                                                
  File "/home/apps/mcm/birb/minecraft_manager/signals/pre_delete.py", line 2, in attachment_delete                                                                                                                                           
    instance.file.delete(False)                                                                                                                                                                                                              
AttributeError: 'Migration' object has no attribute 'file'   
It appears this [signal](https://git.canopymc.net/Canopy/minecraft_manager/src/branch/master/signals/pre_delete.py#L2) causes issues while running migrations. The `instance` parameter does not allways have the `file` attribute. ``` (ve) apps@nest:~/mcm/birb$ ./manage.py migrate django_coreprotect zero Operations to perform: Unapply all migrations: django_coreprotect Running migrations: Rendering model states... DONE Unapplying django_coreprotect.0001_initial...Traceback (most recent call last): File "./manage.py", line 21, in <module> main() File "./manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 232, in handle post_migrate_state = executor.migrate( File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 121, in migrate state = self._migrate_all_backwards(plan, full_plan, fake=fake) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 196, in _migrate_all_backwards self.unapply_migration(states[migration], migration, fake=fake) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/executor.py", line 275, in unapply_migration self.recorder.record_unapplied(migration.app_label, migration.name) File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 88, in record_unapplied self.migration_qs.filter(app=app, name=name).delete() File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/models/query.py", line 711, in delete deleted, _rows_count = collector.delete() File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/db/models/deletion.py", line 287, in delete signals.pre_delete.send( File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 173, in send return [ File "/home/apps/mcm/ve/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 174, in <listcomp> (receiver, receiver(signal=self, sender=sender, **named)) File "/home/apps/mcm/birb/minecraft_manager/signals/pre_delete.py", line 2, in attachment_delete instance.file.delete(False) AttributeError: 'Migration' object has no attribute 'file' ```
Etzelia commented 2021-07-15 18:52:11 +00:00 (Migrated from git.canopymc.net)
https://docs.djangoproject.com/en/3.2/topics/signals/#connecting-to-signals-sent-by-specific-senders
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Minecraft/minecraft_manager#11
There is no content yet.