Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin error when using some of file storage backends #302

Open
machakux opened this issue Oct 17, 2024 · 0 comments
Open

Admin error when using some of file storage backends #302

machakux opened this issue Oct 17, 2024 · 0 comments

Comments

@machakux
Copy link

machakux commented Oct 17, 2024

NotImplementedError: This backend doesn't support absolute paths is raised when opening e-mail messages with attachments in admin interface when using some remote file storage backends (via django-storages).

I think the error is a result of trying to open attachments files directly using open() function; For example as in Message._rehydrate() method.

May be a possibe soulution could be replacing direct calls to open() with open method from django storage backends; For example using something like attachment.document.open('rb') instead of open(attachment.document.path, 'rb')

Sample error log

Internal Server Error: /admin/django_mailbox/message/<id>/change/
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/db/models/options.py", line 676, in get_field
  return self.fields_map[field_name]
         ~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'envelope_headers'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 290, in lookup_field
  f = _get_non_gfk_field(opts, name)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 330, in _get_non_gfk_field
  field = opts.get_field(name)
          ^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/options.py", line 678, in get_field
      raise FieldDoesNotExist(
django.core.exceptions.FieldDoesNotExist: Message has no field named 'envelope_headers'

During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
  response = get_response(request)
             ^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 220, in _get_response
  response = response.render()
             ^^^^^^^^^^^^^^^^^

 ...

            ^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/helpers.py", line 275, in contents
  f, attr, value = lookup_field(field, obj, model_admin)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 299, in lookup_field
  value = attr(obj)
          ^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django_mailbox/admin.py", line 76, in envelope_headers
  email = msg.get_email_object()
          ^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django_mailbox/models.py", line 798, in get_email_object
  self._email_object = self._rehydrate(flat)
                       ^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django_mailbox/models.py", line 699, in _rehydrate
  self._rehydrate(part)
File "/usr/local/lib/python3.11/site-packages/django_mailbox/models.py", line 728, in _rehydrate
  with open(attachment.document.path, 'rb') as f:
            ^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/models/fields/files.py", line 65, in path
  return self.storage.path(self.name)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/files/storage/base.py", line 137, in path
  raise NotImplementedError("This backend doesn't support absolute paths.")

NotImplementedError: This backend doesn't support absolute paths

@machakux machakux changed the title Admin error when using some file storage backends Admin error when using some of file storage backends Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant