cfe-lab / Kive

Archival and automation of bioinformatic pipelines and data
https://cfe-lab.github.io/Kive
BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

Tar file breaks dataset viewer #1089

Open donkirkby opened 3 years ago

donkirkby commented 3 years ago

A container generated a tar file of png files, and then the server displayed an error page when we went to view the dataset.

Traceback:

File "/opt/venv_kive/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/opt/venv_kive/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/opt/venv_kive/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/venv_kive/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "/usr/local/share/Kive/kive/librarian/views.py" in dataset_view
  144.                 sample_content = data_handle.read(1000)

File "/usr/lib64/python3.6/encodings/ascii.py" in decode
  26.         return codecs.ascii_decode(input, self.errors)[0]

Exception Type: UnicodeDecodeError at /dataset_view/1820806
Exception Value: 'ascii' codec can't decode byte 0x89 in position 1536: ordinal not in range(128)

I think we use a utility that tries to identify binary files, maybe it doesn't work with tar files. We should be able to catch the exception and then treat the file as binary.

donkirkby commented 2 years ago

I'm seeing the same error with PDF files. Workaround: download them through the API.