--- /dev/null
+.. change::
+ :tags: bug, sql
+ :versions: 1.3.0b1
+
+ Fixed issue where the "ambiguous literal" error message used when
+ interpreting literal values as SQL expression values would encounter a
+ tuple value, and fail to format the message properly. Pull request courtesy
+ Miguel Ventura.
raise exc.ArgumentError("Ambiguous literal: %r. Use the 'text()' "
"function to indicate a SQL expression "
"literal, or 'literal()' to indicate a "
- "bound value." % element)
+ "bound value." % (element, ))
else:
return element
-from sqlalchemy.testing import assert_raises, eq_
+from sqlalchemy.testing import assert_raises, eq_, assert_raises_message
from sqlalchemy.testing import fixtures, AssertsCompiledSQL
from sqlalchemy import (
testing, exc, case, select, literal_column, text, and_, Integer, cast,
(0, 6, 'pk_6_data')
]
+ def test_literal_interpretation_ambiguous(self):
+ assert_raises_message(
+ exc.ArgumentError,
+ r"Ambiguous literal: 'x'. Use the 'text\(\)' function",
+ case, [("x", "y")]
+ )
+
+ def test_literal_interpretation_ambiguous_tuple(self):
+ assert_raises_message(
+ exc.ArgumentError,
+ r"Ambiguous literal: \('x', 'y'\). Use the 'text\(\)' function",
+ case, [(("x", "y"), "z")]
+ )
+
def test_literal_interpretation(self):
t = table('test', column('col1'))
- assert_raises(exc.ArgumentError, case, [("x", "y")])
-
self.assert_compile(
case([("x", "y")], value=t.c.col1),
"CASE test.col1 WHEN :param_1 THEN :param_2 END")