Resolve ""This backend doesn't support absolute paths" when uploading certain tracks"
Closes #857 (closed)
Quite a simple fix: instead of using the file path to guess the mimetype (when guessing from file content fails), which is unsupported on S3 storages, we use the file name, which works seamlessly!
@funkwhale/reviewers-python
Merge request reports
Activity
changed milestone to %0.19.1
added AreaBackend ComponentImport StatusReview wanted TypeBug labels
36 36 result = utils.get_audio_file_data(f) 37 37 38 38 assert result == expected 39 40 41 def test_guess_mimetype_dont_crash_with_s3(factories, mocker, settings): 42 """See #857""" 43 settings.DEFAULT_FILE_STORAGE = "funkwhale_api.common.storage.ASCIIS3Boto3Storage" 44 mocker.patch("magic.from_buffer", return_value="none") 45 f = factories["music.Upload"].build(audio_file__filename="test.mp3") Plus a reminder to run the test without the fix, just to check :-)
I did this one in TDD mode and confirm it fails without my code fix :D
I'm confused: isn't the point of this test to make sure that it doesn't crash when the filename contains a full path?
The error message is a bit misleading, the root cause of the error is that django cannot retrieve a file path for S3 backend, because it makes no sense. It's not related to the content of the filename, but of the type of storage instead: if we try to access
file.path
on any S3 file, it will crash the same.The only reason it wasn't crashing consistently before is that the access to
file.path
was done in aif
clause, and only as a last resort when we couldn't guess the mimetype of a file based on its content.
mentioned in commit 4010496b