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):