TrustPoint-Project / trustpoint

MIT License
5 stars 0 forks source link

auto_delete_files_on_delete fires on deletion of any database model. #4

Closed Aircoookie closed 8 months ago

Aircoookie commented 8 months ago

This method should only fire on deletion of an IssuingCa model, however it appears to be called if any model object is deleted and raises e.g.

AttributeError: 'Device' object has no attribute 'p12'

Also affects admin login/logout, as that deletes a Session.

Workaround (ideally this method would not be called at all)

if not isinstance(instance, IssuingCa): return
AlexHx8472 commented 8 months ago

Noticed that too. I forgot to check the sender. Fixed it with:

@receiver(models.signals.post_delete)
def auto_delete_file_on_delete(sender: models.Model, instance: IssuingCa, **kwargs: Any) -> None:
    if sender == IssuingCa:
        <do something>