coddingtonbear / django-mailbox

Import mail from POP3, IMAP, local email mailboxes or directly from Postfix or Exim4 into your Django application automatically.
MIT License
356 stars 164 forks source link

MessageAttachment __str__ change #283

Closed Pietro395 closed 8 months ago

Pietro395 commented 8 months ago

Small change to MessageAttachment str method.

Previously, this exception occurred when "Saving and continue edit" a Message by deleting an attachment


  File "/home/intacloud/env/lib/python3.8/site-packages/django/contrib/admin/utils.py", line 571, in construct_change_message
    "object": str(deleted_object),
  File "/home/intacloud/env/lib/python3.8/site-packages/django_mailbox/models.py", line 867, in __str__
    return self.document.url
  File "/home/intacloud/env/lib/python3.8/site-packages/django/db/models/fields/files.py", line 66, in url
    self._require_file()
  File "/home/intacloud/env/lib/python3.8/site-packages/django/db/models/fields/files.py", line 41, in _require_file
    raise ValueError(
ValueError: The 'document' attribute has no file associated with it
Pietro395 commented 8 months ago

Hi @Pietro395, it's not clear how / why we can have an attachment without the message it relates to, but the str should display more about itself than its parent IMO. I added a suggestion

Hi @pfouque , you are right. Tomorrow I'll do a quick test of the change

Pietro395 commented 8 months ago

LGTM @pfouque