]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where so-called "literal render" of :func:`.bindparam`
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Feb 2014 17:03:46 +0000 (12:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Feb 2014 17:03:46 +0000 (12:03 -0500)
constructs would fail if the bind were constructed with a callable,
rather than a direct value.  This prevented ORM expressions
from being rendered with the "literal_binds" compiler flag.

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/compiler.py
test/sql/test_compiler.py

index 8e5fea1a7e3d98bf2ad4135b67e3313f576f7a4e..d452c4bb3cae2e96cd9ee44855774dd19bcb8caf 100644 (file)
 .. changelog::
     :version: 0.9.3
 
+    .. change::
+        :tags: bug, sql
+
+        Fixed bug where so-called "literal render" of :func:`.bindparam`
+        constructs would fail if the bind were constructed with a callable,
+        rather than a direct value.  This prevented ORM expressions
+        from being rendered with the "literal_binds" compiler flag.
+
     .. change::
         :tags: bug, orm
         :tickets: 2935
index 673e5f89b7b1db8b409dd728c8be6b9fd24d42ed..d4b080720d5056141c30610a6ae8569729640b8c 100644 (file)
@@ -969,7 +969,7 @@ class SQLCompiler(Compiled):
         if literal_binds or \
             (within_columns_clause and \
                 self.ansi_bind_rules):
-            if bindparam.value is None:
+            if bindparam.value is None and bindparam.callable is None:
                 raise exc.CompileError("Bind parameter '%s' without a "
                                         "renderable value not allowed here."
                                         % bindparam.key)
@@ -1005,7 +1005,7 @@ class SQLCompiler(Compiled):
         return self.bindparam_string(name, **kwargs)
 
     def render_literal_bindparam(self, bindparam, **kw):
-        value = bindparam.value
+        value = bindparam.effective_value
         return self.render_literal_value(value, bindparam.type)
 
     def render_literal_value(self, value, type_):
index cd9d318645823e3104f6e42a948bd05c5c9e0f51..25aa78b0353c7579b36a01bc49306efd25716a18 100644 (file)
@@ -1191,6 +1191,13 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
             dialect=dialect
         )
 
+        # test callable
+        self.assert_compile(
+            select([table1.c.myid == bindparam("foo", callable_=lambda: 5)]),
+            "SELECT mytable.myid = 5 AS anon_1 FROM mytable",
+            dialect=dialect
+        )
+
         assert_raises_message(
             exc.CompileError,
             "Bind parameter 'foo' without a renderable value not allowed here.",