Skip to content
Snippets Groups Projects

Resolve ""This backend doesn't support absolute paths" when uploading certain tracks"

Merged Agate requested to merge 857-s3-absolute-bath into master
1 unresolved thread

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

Edited by Agate

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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")
  • 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?

    Plus a reminder to run the test without the fix, just to check :-)

  • Author Maintainer

    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 a if clause, and only as a last resort when we couldn't guess the mimetype of a file based on its content.

  • Please register or sign in to reply
  • Agate mentioned in commit 4010496b

    mentioned in commit 4010496b

  • merged

  • Please register or sign in to reply
    Loading