diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-27 19:54:49 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-27 19:54:49 -0500 |
| commit | e21cd0d95fb6cdcb4e10ea78abd5626bb92c37c3 (patch) | |
| tree | cf734e703d24fc415727279cb137d97858674cd7 /test/sql | |
| parent | c2f86c92b1fbb4e855161bd509d3057f86ed7a74 (diff) | |
| download | sqlalchemy-e21cd0d95fb6cdcb4e10ea78abd5626bb92c37c3.tar.gz | |
- Fixed bug in :func:`.tuple_` construct where the "type" of essentially
the first SQL expression would be applied as the "comparison type"
to a compared tuple value; this has the effect in some cases of an
inappropriate "type coersion" occurring, such as when a tuple that
has a mix of String and Binary values improperly coerces target
values to Binary even though that's not what they are on the left
side. :func:`.tuple_` now expects heterogeneous types within its
list of values.
fixes #2977
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_operators.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index d46a9fbd2..1001e598c 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -7,7 +7,7 @@ from sqlalchemy.sql.expression import BinaryExpression, \ UnaryExpression, select, union, func, tuple_ from sqlalchemy.sql import operators, table import operator -from sqlalchemy import String, Integer +from sqlalchemy import String, Integer, LargeBinary from sqlalchemy import exc from sqlalchemy.engine import default from sqlalchemy.sql.elements import _literal_as_text @@ -1628,3 +1628,23 @@ class CustomOpTest(fixtures.TestBase): assert operators.is_comparison(op1) assert not operators.is_comparison(op2) +class TupleTypingTest(fixtures.TestBase): + + def _assert_types(self, expr): + eq_(expr.clauses[0].type._type_affinity, Integer) + eq_(expr.clauses[1].type._type_affinity, String) + eq_(expr.clauses[2].type._type_affinity, LargeBinary()._type_affinity) + + def test_type_coersion_on_eq(self): + a, b, c = column('a', Integer), column('b', String), column('c', LargeBinary) + t1 = tuple_(a, b, c) + expr = t1 == (3, 'hi', 'there') + self._assert_types(expr.right) + + def test_type_coersion_on_in(self): + a, b, c = column('a', Integer), column('b', String), column('c', LargeBinary) + t1 = tuple_(a, b, c) + expr = t1.in_([(3, 'hi', 'there'), (4, 'Q', 'P')]) + eq_(len(expr.right.clauses), 2) + for elem in expr.right.clauses: + self._assert_types(elem) |
