--- /dev/null
+.. change::
+ :tags: bug, sql
+ :tickets: 9313
+
+ Fixed issue where element types of a tuple value would be hardcoded to take
+ on the types from a compared-to tuple, when the comparison were using the
+ :meth:`.ColumnOperators.in_` operator. This was inconsistent with the usual
+ way that types are determined for a binary expression, which is that the
+ actual element type on the right side is considered first before applying
+ the left-hand-side type.
self._is_crud = True
if type_ is None:
- if expanding and value:
- check_value = value[0]
+ if expanding:
+ if value:
+ check_value = value[0]
+ else:
+ check_value = type_api._NO_VALUE_IN_LIST
else:
check_value = value
if _compared_to_type is not None:
_compared_to_operator=operator,
unique=True,
expanding=True,
- type_=self.type,
+ type_=type_,
+ _compared_to_type=self.type,
)
else:
return Tuple(
for item_type in types
]
+ def coerce_compared_value(
+ self, op: Optional[OperatorType], value: Any
+ ) -> TypeEngine[Any]:
+
+ if value is type_api._NO_VALUE_IN_LIST:
+ return super().coerce_compared_value(op, value)
+ else:
+ return TupleType(
+ *[
+ typ.coerce_compared_value(op, elem)
+ for typ, elem in zip(self.types, value)
+ ]
+ )
+
def _resolve_values_to_types(self, value: Any) -> TupleType:
if self._fully_typed:
return self
from __future__ import annotations
+from enum import Enum
from types import ModuleType
import typing
from typing import Any
_MatchedOnType = Union["GenericProtocol[Any]", NewType, Type[Any]]
-# replace with pep-673 when applicable
+
+class _NoValueInList(Enum):
+ NO_VALUE_IN_LIST = 0
+ """indicates we are trying to determine the type of an expression
+ against an empty list."""
+
+
+_NO_VALUE_IN_LIST = _NoValueInList.NO_VALUE_IN_LIST
class _LiteralProcessorType(Protocol[_T_co]):
expr = t1 == (3, "hi", b"there")
self._assert_types(expr.right.type.types)
+ def test_tuple_type_left_type_ignored(self):
+ a, b = column("a", sqltypes.Date), column("b", sqltypes.DateTime)
+ c = column("c", sqltypes.Float)
+
+ t1 = tuple_(a, b, c)
+ expr = t1.in_([(3, "hi", b"there")])
+ self._assert_types(expr.right.type.types)
+
class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = "default"