Project

General

Profile

Développement #46790

éviter de crasher quand un fichier n'a plus son contenu dans uploads/

Added by Thomas Noël over 4 years ago.

Status:
Nouveau
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
18 September 2020
Due date:
% Done:

0%

Estimated time:
Patch proposed:
No
Planning:
No

Description

Si par malchance ou erreur un fichier uploads/xxx a été effacé, la vue JSON du fichier explose :

Exception

  type = '<class 'FileNotFoundError'>', value = '[Errno 2] No such file or directory: '/var/lib/wcs/xxxx/uploads/ed4d7c5dca66fb771eaed034b0aaaf7daf0af64fbe98e4cd69ffa10cfb60d5ef''

Trace (appels les plus récents en premier)

  File "/usr/lib/python3/dist-packages/wcs/qommon/upload_storage.py", line 74, in get_content
    72         if hasattr(self, 'qfilename'):
    73             filename = os.path.join(get_publisher().app_dir, 'uploads', self.qfilename)
>   74             return open(filename, 'rb').read()
    75         return None
    76 

  locals: 
     filename = '/var/lib/wcs/xxxx/uploads/ed4d7c5dca66fb771eaed034b0aaaf7daf0af64fbe98e4cd69ffa10cfb60d5ef'
     self = <PicklableUpload at 7f8a02af7128: piece d'identité.pdf>

  File "/usr/lib/python3/dist-packages/wcs/qommon/upload_storage.py", line 146, in get_json_value
   144         }
   145         if include_file_content:
>  146             value['content'] = force_text(base64.b64encode(upload.get_content()))
   147         return value
   148 

  locals: 
     include_file_content = True
     self = <wcs.qommon.upload_storage.UploadStorage object at 0x7f8a02af8c50>
     upload = <PicklableUpload at 7f8a02af7128: piece d'identité.pdf>
     value = {'content_type': 'application/pdf', 'filename': 'piece d_identité.pdf'}

  File "/usr/lib/python3/dist-packages/wcs/qommon/upload_storage.py", line 85, in get_json_value
    83     def get_json_value(self, include_file_content=True):
    84         return get_storage_object(getattr(self, 'storage', None)).get_json_value(
>   85                 self, include_file_content=include_file_content)
    86 
    87     def can_thumbnail(self):

On pourrait tenter ici que le get_json_value renvoie un None, comme si le fichier n'existait pas.

Also available in: Atom PDF