postgresql: only pass username and password if they are set
Passing None makes psycopg2 >= 2.7 use the string "None" as a role rather than nothing like it used to do. Change-Id: Idf575930ea363a7e7e613ebdca4595a9ca8f7389
This commit is contained in:
parent
45220d4d50
commit
6eea97c3ef
|
@ -178,8 +178,7 @@ class PostgresDriver(coordination.CoordinationDriver):
|
||||||
self._options = utils.collapse(options)
|
self._options = utils.collapse(options)
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
self._conn = PostgresDriver.get_connection(self._parsed_url,
|
self._conn = self.get_connection(self._parsed_url, self._options)
|
||||||
self._options)
|
|
||||||
|
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
self._conn.close()
|
self._conn.close()
|
||||||
|
@ -216,15 +215,17 @@ class PostgresDriver(coordination.CoordinationDriver):
|
||||||
host = options.get("host") or parsed_url.hostname
|
host = options.get("host") or parsed_url.hostname
|
||||||
port = options.get("port") or parsed_url.port
|
port = options.get("port") or parsed_url.port
|
||||||
dbname = options.get("dbname") or parsed_url.path[1:]
|
dbname = options.get("dbname") or parsed_url.path[1:]
|
||||||
username = parsed_url.username
|
kwargs = {}
|
||||||
password = parsed_url.password
|
if parsed_url.username is not None:
|
||||||
|
kwargs["username"] = parsed_url.username
|
||||||
|
if parsed_url.password is not None:
|
||||||
|
kwargs["password"] = parsed_url.password
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return psycopg2.connect(host=host,
|
return psycopg2.connect(host=host,
|
||||||
port=port,
|
port=port,
|
||||||
user=username,
|
database=dbname,
|
||||||
password=password,
|
**kwargs)
|
||||||
database=dbname)
|
|
||||||
except psycopg2.Error as e:
|
except psycopg2.Error as e:
|
||||||
utils.raise_with_cause(coordination.ToozConnectionError,
|
utils.raise_with_cause(coordination.ToozConnectionError,
|
||||||
_format_exception(e),
|
_format_exception(e),
|
||||||
|
|
Loading…
Reference in New Issue