From dd2ff2af56b99d69d508fa6169be4011283593e2 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 16 Jun 2021 23:55:11 +0100 Subject: [PATCH] Fix regression with named `sql.Placeholder` Close #1291. --- NEWS | 6 ++++++ lib/sql.py | 2 +- tests/test_sql.py | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8b7818a3..c6f9ab1e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,12 @@ Current release --------------- +What's new in psycopg 2.9.1 +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Fix regression with named `sql.Placeholder` (:ticket:`1291`). + + What's new in psycopg 2.9 ------------------------- diff --git a/lib/sql.py b/lib/sql.py index 1c780902..13548da4 100644 --- a/lib/sql.py +++ b/lib/sql.py @@ -442,7 +442,7 @@ class Placeholder(Composable): def as_string(self, context): if self._wrapped is not None: - return f"%({self._wrapped})" + return f"%({self._wrapped})s" else: return "%s" diff --git a/tests/test_sql.py b/tests/test_sql.py index 8fb1f114..407c07df 100755 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -393,6 +393,10 @@ class PlaceholderTest(ConnectingTestCase): self.assert_(sql.Placeholder('foo') != sql.Placeholder()) self.assert_(sql.Placeholder('foo') != sql.Literal('foo')) + def test_as_string(self): + self.assertEqual(sql.Placeholder().as_string(self.conn), "%s") + self.assertEqual(sql.Placeholder('foo').as_string(self.conn), "%(foo)s") + class ValuesTest(ConnectingTestCase): def test_null(self):