]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- _literal_as_text raises if the incoming arg is not a Visitable or basestring.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 16:24:57 +0000 (11:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 16:24:57 +0000 (11:24 -0500)
[ticket:1847]

lib/sqlalchemy/sql/expression.py
test/sql/test_compiler.py

index ede3235c5996d32ec498fe35394c28f6ba67ea6a..3cfe0a14c5f6cf1700db2422d8b1e1a6a1c24605 100644 (file)
@@ -1056,8 +1056,10 @@ def _column_as_key(element):
 def _literal_as_text(element):
     if hasattr(element, '__clause_element__'):
         return element.__clause_element__()
-    elif not isinstance(element, Visitable):
+    elif isinstance(element, basestring):
         return _TextClause(unicode(element))
+    elif not isinstance(element, Visitable):
+        raise exc.ArgumentError("SQL expression object or string expected.")
     else:
         return element
 
index 7dbb6fc6f32dcc4a83e9cc2c9abf0bb7dc5b599f..f6cffc11635c7e36cda19d0f994f3f3db9311039 100644 (file)
@@ -2263,6 +2263,18 @@ class SelectTest(TestBase, AssertsCompiledSQL):
                 expected,
                 dialect=dialect
             )
+
+    def test_literal_as_text_fromstring(self):
+        self.assert_compile(
+            and_("a", "b"),
+            "a AND b"
+        )
+        
+    def test_literal_as_text_nonstring_raise(self):
+        assert_raises(exc.ArgumentError,
+            and_, ("a",), ("b",)
+        )
+        
         
 class CRUDTest(TestBase, AssertsCompiledSQL):
     def test_insert(self):