tortoise-orm
tortoise-orm copied to clipboard
Percent encoded usernames in database URLs are passed to drivers without decoding
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.
I have an idea: pass a db_url such as "postgres://first%40last:example@localhost/db" to asyncpg.create_pool as the dsn argument...
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.