From 44d8edfd8c3bcaa3167e84fd11cc62b43bfd3af5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 1 Mar 2017 20:12:13 +0000 Subject: [PATCH] Ignore None arguments passed to make_dsn() Close #517. --- NEWS | 7 +++++++ lib/extensions.py | 3 +++ tests/test_connection.py | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/NEWS b/NEWS index 8fc14cd0..1b934b30 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,13 @@ 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 ------------------------- diff --git a/lib/extensions.py b/lib/extensions.py index 9fee5510..00d71f0a 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -162,6 +162,9 @@ def make_dsn(dsn=None, **kwargs): "you can't specify both 'database' and 'dbname' arguments") 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: tmp = parse_dsn(dsn) tmp.update(kwargs) diff --git a/tests/test_connection.py b/tests/test_connection.py index a9525b4d..dae0560f 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -459,6 +459,10 @@ class MakeDsnTestCase(ConnectingTestCase): dsn = ext.make_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) def test_url_is_cool(self): url = 'postgresql://tester:secret@/test?application_name=wat'