tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

Percent encoded usernames in database URLs are passed to drivers without decoding

Open IlyaKhalafi opened this issue 1 month ago • 2 comments

On current develop, database URL passwords are percent decoded but usernames are not.

from tortoise.backends.base.config_generator import expand_db_url

config = expand_db_url("asyncpg://first%40last:example@localhost/db")
print(config["credentials"]["user"])

This prints first%40last instead of first@last. Drivers then receive a different username from the one represented by the URL. Literal plus signs and already parsed query-string usernames should remain unchanged.

IlyaKhalafi avatar Oct 24 '26 13:10 IlyaKhalafi

I have an idea: pass a db_url such as "postgres://first%40last:example@localhost/db" to asyncpg.create_pool as the dsn argument...

waketzheng avatar Oct 25 '26 04:10 waketzheng

That could work for asyncpg. Tortoise's own query options such as minsize and schema would need to be stripped from the DSN first, since asyncpg treats unknown URI options as server settings.

IlyaKhalafi avatar Oct 25 '26 05:10 IlyaKhalafi