metaflow-service
metaflow-service copied to clipboard
fix: percent-encode forward slash in database connection string
The DB connection string used urllib.parse.quote to percent-encode the username and password. However, quote has a default kwarg safe="/" that does NOT percent-encode forward slashes. If the username or password includes a forward slash, then the resulting connection string may be rejected by the postgres client.
For example, when the password contains an unescaped forward slash, psycopg incorrectly parses the password field as a port.
>>> import psycopg2
>>> conn = "postgresql://user:abc/123@localhost:5432/db"
>>> psycopg2.connect(conn)
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
psycopg2.connect(conn)
~~~~~~~~~~~~~~~~^^^^^^
File "/Users/willdaly/repos/metaflow-service/.venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: invalid integer value "abc" for connection option "port"
Fix it by percent-escaping forward slashes in all DB connection strings.
incidentally, I discovered this while trying to use AWS RDS IAM. AWS puts forward slashes in its tokens.
It seems that linter check failed. Can you address that so that we can merge this PR?