Fix regression with named sql.Placeholder

Close #1291.
This commit is contained in:
Daniele Varrazzo 2021-06-16 23:55:11 +01:00
parent b46424447f
commit dd2ff2af56
3 changed files with 11 additions and 1 deletions

6
NEWS
View File

@ -1,6 +1,12 @@
Current release 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 What's new in psycopg 2.9
------------------------- -------------------------

View File

@ -442,7 +442,7 @@ class Placeholder(Composable):
def as_string(self, context): def as_string(self, context):
if self._wrapped is not None: if self._wrapped is not None:
return f"%({self._wrapped})" return f"%({self._wrapped})s"
else: else:
return "%s" return "%s"

View File

@ -393,6 +393,10 @@ class PlaceholderTest(ConnectingTestCase):
self.assert_(sql.Placeholder('foo') != sql.Placeholder()) self.assert_(sql.Placeholder('foo') != sql.Placeholder())
self.assert_(sql.Placeholder('foo') != sql.Literal('foo')) 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): class ValuesTest(ConnectingTestCase):
def test_null(self): def test_null(self):