Ignore None arguments passed to make_dsn()

Close #517.
This commit is contained in:
Daniele Varrazzo 2017-03-01 20:12:13 +00:00
parent 455f51c36c
commit 44d8edfd8c
3 changed files with 14 additions and 0 deletions

7
NEWS
View File

@ -1,6 +1,13 @@
Current release Current release
--------------- ---------------
What's new in psycopg 2.7.1
---------------------------
- Ignore `!None` arguments passed to `~psycopg2.connect()` and
`~psycopg2.extensions.make_dsn()` (:ticket:`#517`).
What's new in psycopg 2.7 What's new in psycopg 2.7
------------------------- -------------------------

View File

@ -162,6 +162,9 @@ def make_dsn(dsn=None, **kwargs):
"you can't specify both 'database' and 'dbname' arguments") "you can't specify both 'database' and 'dbname' arguments")
kwargs['dbname'] = kwargs.pop('database') kwargs['dbname'] = kwargs.pop('database')
# Drop the None arguments
kwargs = dict((k, v) for (k, v) in kwargs.iteritems() if v is not None)
if dsn is not None: if dsn is not None:
tmp = parse_dsn(dsn) tmp = parse_dsn(dsn)
tmp.update(kwargs) tmp.update(kwargs)

View File

@ -459,6 +459,10 @@ class MakeDsnTestCase(ConnectingTestCase):
dsn = ext.make_dsn(dsnin) dsn = ext.make_dsn(dsnin)
self.assertEqual(dsn, dsnin) self.assertEqual(dsn, dsnin)
def test_null_args(self):
dsn = ext.make_dsn("dbname=foo", user="bar", password=None)
self.assertDsnEqual(dsn, "dbname=foo user=bar")
@skip_before_libpq(9, 2) @skip_before_libpq(9, 2)
def test_url_is_cool(self): def test_url_is_cool(self):
url = 'postgresql://tester:secret@/test?application_name=wat' url = 'postgresql://tester:secret@/test?application_name=wat'