summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-22 10:57:00 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-22 23:29:11 -0400
commit63191fbef63ebfbf57e7b66bd6529305fc62c605 (patch)
tree7572c1bdcecbc4e3640e5860c42a8b031f595bce /lib/sqlalchemy
parentfe2045fb1c767436ed1e32359fe005dabead504a (diff)
downloadsqlalchemy-63191fbef63ebfbf57e7b66bd6529305fc62c605.tar.gz
properly type array element in any() / all()
Fixed bug in :class:`.ARRAY` datatype in combination with :class:`.Enum` on PostgreSQL where using the ``.any()`` method to render SQL ANY(), given members of the Python enumeration as arguments, would produce a type adaptation failure on all drivers. Fixes: #6515 Change-Id: Ia1e3b4e10aaf264ed436ce6030d105fc60023433
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 64d6ea81b..65b97d565 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -2715,9 +2715,11 @@ class ARRAY(
__slots__ = ()
+ type: ARRAY
+
def _setup_getitem(self, index):
- arr_type = cast(ARRAY, self.type)
+ arr_type = self.type
return_type: TypeEngine[Any]
@@ -2784,10 +2786,18 @@ class ARRAY(
elements = util.preloaded.sql_elements
operator = operator if operator else operators.eq
+ arr_type = self.type
+
# send plain BinaryExpression so that negate remains at None,
# leading to NOT expr for negation.
return elements.BinaryExpression(
- coercions.expect(roles.ExpressionElementRole, other),
+ coercions.expect(
+ roles.BinaryElementRole,
+ element=other,
+ operator=operator,
+ expr=self.expr,
+ bindparam_type=arr_type.item_type,
+ ),
elements.CollectionAggregate._create_any(self.expr),
operator,
)
@@ -2828,10 +2838,18 @@ class ARRAY(
elements = util.preloaded.sql_elements
operator = operator if operator else operators.eq
+ arr_type = self.type
+
# send plain BinaryExpression so that negate remains at None,
# leading to NOT expr for negation.
return elements.BinaryExpression(
- coercions.expect(roles.ExpressionElementRole, other),
+ coercions.expect(
+ roles.BinaryElementRole,
+ element=other,
+ operator=operator,
+ expr=self.expr,
+ bindparam_type=arr_type.item_type,
+ ),
elements.CollectionAggregate._create_all(self.expr),
operator,
)