Skip to content

Commit

Permalink
Merge pull request #1051 from dbcli/pr1035
Browse files Browse the repository at this point in the history
 Fix usage of pgservice #1035
  • Loading branch information
amjith authored May 6, 2019
2 parents 30c7889 + dc43430 commit 9f2d61b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bug fixes:
* Fix for "no attribute KeyringLocked" (#1040). (Thanks: `Irina Truong`_)
* Pgcli no longer works with password containing spaces (#1043). (Thanks: `Irina Truong`_)
* Load keyring only when keyring is enabled in the config file (#1041). (Thanks: `Zhaolong Zhu`_)
* Fix the broken support for pgservice . (Thanks: `Xavier Francisco`_)

Internal:
---------
Expand Down Expand Up @@ -969,4 +970,4 @@ Improvements:
.. _`Nathan Verzemnieks`: https://github.com/njvrzm
.. _`raylu`: https://github.com/raylu
.. _`Zhaolong Zhu`: https://github.com/zzl0

.. _`Xavier Francisco`: https://github.com/Qu4tro
18 changes: 13 additions & 5 deletions pgcli/pgexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,22 @@ def connect(self, database=None, user=None, password=None, host=None,
'dsn': dsn,
}
new_params.update(kwargs)

if new_params['dsn']:
new_params = {
'dsn': new_params['dsn'],
'password': new_params['password']
}

if new_params['password']:
new_params['dsn'] = "{0} password={1}".format(
new_params['dsn'], new_params.pop('password')
)

conn_params.update({
k: unicode2utf8(v) for k, v in new_params.items() if v is not None
k: unicode2utf8(v) for k, v in new_params.items() if v
})

if 'password' in conn_params and 'dsn' in conn_params:
conn_params['dsn'] = make_dsn(
conn_params['dsn'], password=conn_params.pop('password'))

conn = psycopg2.connect(**conn_params)
cursor = conn.cursor()
conn.set_client_encoding('utf8')
Expand Down

0 comments on commit 9f2d61b

Please sign in to comment.