From: Mike Bayer Date: Sun, 28 Nov 2010 16:24:57 +0000 (-0500) Subject: - _literal_as_text raises if the incoming arg is not a Visitable or basestring. X-Git-Tag: rel_0_7b1~237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59a177a4c0bd69863e011e0f1c40e5b87fff99d3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - _literal_as_text raises if the incoming arg is not a Visitable or basestring. [ticket:1847] --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index ede3235c59..3cfe0a14c5 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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 diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 7dbb6fc6f3..f6cffc1163 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -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):