pydantic-core icon indicating copy to clipboard operation
pydantic-core copied to clipboard

pydantic_core.MultiHostUrl and pydantic_core.Url not support password as empty string

Open duchuyvp opened this issue 1 year ago • 1 comments

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

duchuyvp avatar Jan 03 '24 08:01 duchuyvp

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.

davidhewitt avatar Jan 08 '24 17:01 davidhewitt

Marking as resolved, given the analysis above. Thanks @davidhewitt !

sydney-runkle avatar Aug 16 '24 17:08 sydney-runkle