Skip to content

Commit

Permalink
[postgres] dont use urlquote_plus (#7723)
Browse files Browse the repository at this point in the history
### Summary & Motivation

`quote_plus` replaces spaces with plus, which causes users passwords to not work.

https://docs.python.org/3.8/library/urllib.parse.html#urlparse.parse_qs

blame rev is https://dagster.phacility.com/D1830, not sure why i used `quote_plus` originally.

resolves #5452


### How I Tested These Changes

updated test to include spaces
  • Loading branch information
alangenfeld committed May 4, 2022
1 parent ae55df0 commit 5e32caa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging
import time
from contextlib import contextmanager
from urllib.parse import quote
from urllib.parse import quote_plus as urlquote
from urllib.parse import urlencode
from urllib.parse import quote, urlencode

import psycopg2
import psycopg2.errorcodes
Expand Down Expand Up @@ -60,7 +58,7 @@ def pg_url_from_config(config_value):


def get_conn_string(username, password, hostname, db_name, port="5432", params=None):
uri = f"postgresql://{urlquote(username)}:{urlquote(password)}@{hostname}:{port}/{db_name}"
uri = f"postgresql://{quote(username)}:{quote(password)}@{hostname}:{port}/{db_name}"

if params:
query_string = f"{urlencode(params, quote_via=quote)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_specify_pg_params(hostname):

def test_conn_str():
username = "has@init"
password = "full:of:junk!@?"
password = ":full: of junk!@?"
db_name = "dagster"
hostname = "database-city.com"

Expand All @@ -239,7 +239,7 @@ def test_conn_str():
)
assert (
conn_str
== r"postgresql://has%40init:full%3Aof%3Ajunk%21%40%3F@database-city.com:5432/dagster"
== r"postgresql://has%40init:%3Afull%3A%20of%20junk%21%40%3F@database-city.com:5432/dagster"
)
parsed = urlparse(conn_str)
assert unquote(parsed.username) == username
Expand Down

0 comments on commit 5e32caa

Please sign in to comment.