Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields.Url does not accept file URLs #2249

Open
0xDEC0DE opened this issue Mar 14, 2024 · 0 comments
Open

fields.Url does not accept file URLs #2249

0xDEC0DE opened this issue Mar 14, 2024 · 0 comments

Comments

@0xDEC0DE
Copy link

Steps to reproduce

Run this test case:

import marshmallow as mm
class LOL(mm.Schema):
    url = mm.fields.Url(schemes={'file'})

LOL().load(dict(url="file:///var/storage/somefile.zip"))

Expected result

{'url': 'file:///var/storage/somefile.zip'}

Actual behavior

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 756, in loads
    return self.load(data, many=many, partial=partial, unknown=unknown)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 722, in load
    return self._do_load(
           ^^^^^^^^^^^^^^
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 909, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'url': ['Not a valid URL.']}

Workaround

This works:

LOL().load(dict(url="file://localhost/var/storage/somefile.zip"))

...but the hostname portion is entirely optional with file URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant