#30599: ManifestFilesMixin read_manifest swallows OSError that prevents template
rendering
-------------------------------------------+------------------------
               Reporter:  Matt Layman      |          Owner:  nobody
                   Type:  Uncategorized    |         Status:  new
              Component:  Template system  |        Version:  2.2
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 While using the ManifestStaticFilesStorage, I encountered the ValueError
 shown below.
 {{{
   <trim>
   File "/<some venv>/site-packages/django/contrib/staticfiles/storage.py",
 line 134, in _url
     hashed_name = hashed_name_func(*args)
   File "/<some venv>/site-packages/django/contrib/staticfiles/storage.py",
 line 422, in stored_name
     raise ValueError("Missing staticfiles manifest entry for '%s'" %
 clean_name)
 ValueError: Missing staticfiles manifest entry for 'images/twitter.png'
 }}}

 Further debugging showed that staticfile_storage.hashed_files was empty.
 This was odd to me because staticfiles.json existed on my system in its
 proper location in STATIC_ROOT. Additionally, the 'images/twitter.png'
 existed as a key in the staticfiles.json so I was very confused.

 I did more debugging of the manifest loading process and hit the root
 problem. Reading the manifest file raised a PermissionError because the
 user account running the Django app did not have proper permission to read
 from where the file was stored on the filesystem. Unfortunately,
 
https://github.com/django/django/blob/master/django/contrib/staticfiles/storage.py#L385
 catches any OSError and proceeds by returning no content.

 This was in a Vagrant virtual machine so I switched to the root user to
 bypass any permission errors and the manifest loading worked. I confirmed
 that I was able to load a page without any issue.

 I'd like to suggest that ManifestFilesMixin.read_manifest either a) not
 catch OSError at all to let the system fail so a developer can fix it, b)
 have more granular error handling of different OSError exception
 subclasses, or c) do some kind of logging to hint to the app developer
 that there was a problem.

 I'm making this suggestion because catching this error and proceeding left
 the app in an unrecoverable state. The ValueError listed at the beginning
 of the issue was actually a side effect of the deeper underlying
 PermissionError problem from attempting to read the manifest file.

 If there is any more info you need from me, please let me know. Thanks!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30599>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.fd7425cf048d3e719268e326d5a46227%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to