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

AnyUrl doesn't accept file URLs with implicit host #1983

Closed
torfsen opened this issue Oct 9, 2020 · 3 comments · Fixed by #2434
Closed

AnyUrl doesn't accept file URLs with implicit host #1983

torfsen opened this issue Oct 9, 2020 · 3 comments · Fixed by #2434
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@torfsen
Copy link

torfsen commented Oct 9, 2020

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.5.1
            pydantic compiled: True
                 install path: /shared/conda/envs/ubide-mastr/lib/python3.6/site-packages/pydantic
               python version: 3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21)  [GCC 7.3.0]
                     platform: Linux-5.4.0-48-generic-x86_64-with-debian-buster-sid
     optional deps. installed: []
import pydantic

class MyModel(pydantic.BaseModel):
    url: pydantic.AnyUrl

MyModel(url='file:///foo/bar')

raises:

ValidationError: 1 validation error for MyModel
url
  URL host invalid (type=value_error.url.host)

However, MyModel(url='file://hostname/foo/bar'), i.e. a URL with an explicit hostname, works.

RFC 8089 says that the hostname is optional. Hence I would expect that AnyUrl would accept that.

@torfsen torfsen added the bug V1 Bug related to Pydantic V1.X label Oct 9, 2020
@samuelcolvin
Copy link
Member

I guess we could add host_required like user_required, then make it true for most of the descendant types.

@harshach
Copy link

anyurl doesn't work for JDBC connection URL either "jdbc:mysql://localhost/test" invalid or missing URL scheme (type=value_error.url.scheme)

@dharmveer18
Copy link

I have made Optional[HttpUrl] = None, still not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
4 participants