In-place imports cannot be transcoded
Steps to reproduce
- Import files in-place (e.g. format=ogg).
- Ensure the Upload rows have a source attribute but not a audio_file attribute.
- Try to listen to a transcoded version (e.g. format=mp3), for example using the Subsonic API.
What happens?
The API gives a 500 Internal Server error, with the following traceback (from journalctl -f
):
jan 28 11:43:56 McBeth daphne[18450]: 2019-01-28 11:43:56,673 ERROR Internal Server Error: /api/subsonic/rest/stream.view
jan 28 11:43:56 McBeth daphne[18450]: Traceback (most recent call last):
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
jan 28 11:43:56 McBeth daphne[18450]: response = get_response(request)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
jan 28 11:43:56 McBeth daphne[18450]: response = self.process_exception_by_middleware(e, request)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
jan 28 11:43:56 McBeth daphne[18450]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "/usr/lib/python3.5/contextlib.py", line 30, in inner
jan 28 11:43:56 McBeth daphne[18450]: return func(*args, **kwds)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
jan 28 11:43:56 McBeth daphne[18450]: return view_func(*args, **kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/rest_framework/viewsets.py", line 116, in view
jan 28 11:43:56 McBeth daphne[18450]: return self.dispatch(request, *args, **kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/subsonic/views.py", line 97, in dispatch
jan 28 11:43:56 McBeth daphne[18450]: return super().dispatch(request, *args, **kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/rest_framework/views.py", line 495, in dispatch
jan 28 11:43:56 McBeth daphne[18450]: response = self.handle_exception(exc)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/subsonic/views.py", line 110, in handle_exception
jan 28 11:43:56 McBeth daphne[18450]: return super().handle_exception(exc)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/rest_framework/views.py", line 455, in handle_exception
jan 28 11:43:56 McBeth daphne[18450]: self.raise_uncaught_exception(exc)
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/rest_framework/views.py", line 492, in dispatch
jan 28 11:43:56 McBeth daphne[18450]: response = handler(request, *args, **kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/subsonic/views.py", line 78, in inner
jan 28 11:43:56 McBeth daphne[18450]: return func(self, request, *args, **kwargs)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/subsonic/views.py", line 234, in stream
jan 28 11:43:56 McBeth daphne[18450]: return music_views.handle_serve(upload=upload, user=request.user, format=format)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/music/views.py", line 311, in handle_serve
jan 28 11:43:56 McBeth daphne[18450]: transcoded_version = upload.get_transcoded_version(format)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/music/models.py", line 812, in get_transcoded_version
jan 28 11:43:56 McBeth daphne[18450]: return self.create_transcoded_version(mimetype, format)
jan 28 11:43:56 McBeth daphne[18450]: File "/usr/lib/python3.5/contextlib.py", line 30, in inner
jan 28 11:43:56 McBeth daphne[18450]: return func(*args, **kwds)
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/music/models.py", line 831, in create_transcoded_version
jan 28 11:43:56 McBeth daphne[18450]: output_format=utils.MIMETYPE_TO_EXTENSION[mimetype],
jan 28 11:43:56 McBeth daphne[18450]: File "./funkwhale_api/music/utils.py", line 76, in transcode_file
jan 28 11:43:56 McBeth daphne[18450]: with input.open("rb"):
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/db/models/fields/files.py", line 72, in open
jan 28 11:43:56 McBeth daphne[18450]: self._require_file()
jan 28 11:43:56 McBeth daphne[18450]: File "/srv/funkwhale/virtualenv/lib/python3.5/site-packages/django/db/models/fields/files.py", line 38, in _require_file
jan 28 11:43:56 McBeth daphne[18450]: raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
jan 28 11:43:56 McBeth daphne[18450]: ValueError: The 'audio_file' attribute has no file associated with it.
What is expected?
I expect that the file is successfully transcoded and sent to the browser.
Context
This is Funkwhale version 0.18 running on a private instance, non-docker under nginx.
Funkwhale version(s) affected: 0.18
It seems like the issue is with importing in-place not setting the audio_file attribute, but the transcoding implementation requires this attribute. From a quick look at the code, perhaps it should be self.get_audio_file()
instead of self.audio_file
? I will try changing this and report my experiences in a few hours.