pydantic-core
pydantic-core copied to clipboard
pydantic_core.MultiHostUrl and pydantic_core.Url not support password as empty string
When I create a pydantic_core.Url
with password as empty string as follow (similar with MultiHostUrl
):
uri = pydantic_core.Url.build(
scheme="clickhouse",
username="user",
password="",
host="localhost",
port=8123,
path="ch_db",
)
print(uri.__str__())
I expected clickhouse://user:@localhost:8123/ch_db
(password
as empty string)
But I got clickhouse://user@localhost:8123/ch_db
. I think what I got seems good only when password
is None
.
I faced this problem when try to connect to Clickhouse with clickhouse_connect
clickhouse_connect.get_client(dsn=uri.__str__())
It raised Wrong password error. Even I have a solution is use dns="clickhouse://user:@localhost:8123/ch_db"
but I think it's not good practice.
Is pydantic_core
support create Url with empty password
Looking at the underlying Rust library's issue on this topic: https://github.com/servo/rust-url/issues/793
The conclusion seems to be that the URL standard makes no distinction between user:@
and user@
. The password should be treated as the empty string either way.
https://url.spec.whatwg.org/#url-serializing
So I believe that this is correct, and it is the clickhouse parser which is not compliant here.
Marking as resolved, given the analysis above. Thanks @davidhewitt !