]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Propagate **kw in postgresql distinct on compilation
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Aug 2018 21:18:48 +0000 (17:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Aug 2018 21:20:00 +0000 (17:20 -0400)
Fixed bug in PostgreSQL dialect where compiler keyword arguments such as
``literal_binds=True`` were not being propagated to a DISTINCT ON
expression.

Fixes: #4325
Change-Id: I9949387dceb7fabe889799f42e92423572368b29
(cherry picked from commit 469931514a1517dde82ba56f780c3007c66d5943)

doc/build/changelog/unreleased_12/4325.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_12/4325.rst b/doc/build/changelog/unreleased_12/4325.rst
new file mode 100644 (file)
index 0000000..9d6f38e
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 4325
+
+    Fixed bug in PostgreSQL dialect where compiler keyword arguments such as
+    ``literal_binds=True`` were not being propagated to a DISTINCT ON
+    expression.
index fb911ee2ea7977c8a4137179d86504de27aed47a..8482276d67cdf8988d6139d687d19b0f1763a102 100644 (file)
@@ -1516,7 +1516,7 @@ class PGCompiler(compiler.SQLCompiler):
                 return "DISTINCT "
             elif isinstance(select._distinct, (list, tuple)):
                 return "DISTINCT ON (" + ', '.join(
-                    [self.process(col) for col in select._distinct]
+                    [self.process(col, **kw) for col in select._distinct]
                 ) + ") "
             else:
                 return "DISTINCT ON (" + \
index 5c4d72c6703220a683701ffb9ff31e4b011557cc..6133ab4821680eead771adae2f8350ff1cd14d22 100644 (file)
@@ -1571,6 +1571,13 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL):
             "SELECT DISTINCT ON (t.a) t.id, t.a, t.b FROM t"
         )
 
+    def test_literal_binds(self):
+        self.assert_compile(
+            select([self.table]).distinct(self.table.c.a == 10),
+            "SELECT DISTINCT ON (t.a = 10) t.id, t.a, t.b FROM t",
+            literal_binds=True
+        )
+
     def test_query_plain(self):
         sess = Session()
         self.assert_compile(