From 3b4bbbb2a3d337d0af1ba5ccb0d29d1c48735e83 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 15 Aug 2020 15:08:09 -0400 Subject: Create a real type for Tuple() and handle appropriately in compiler Improved the :func:`_sql.tuple_` construct such that it behaves predictably when used in a columns-clause context. The SQL tuple is not supported as a "SELECT" columns clause element on most backends; on those that do (PostgreSQL, not surprisingly), the Python DBAPI does not have a "nested type" concept so there are still challenges in fetching rows for such an object. Use of :func:`_sql.tuple_` in a :func:`_sql.select` or :class:`_orm.Query` will now raise a :class:`_exc.CompileError` at the point at which the :func:`_sql.tuple_` object is seen as presenting itself for fetching rows (i.e., if the tuple is in the columns clause of a subquery, no error is raised). For ORM use,the :class:`_orm.Bundle` object is an explicit directive that a series of columns should be returned as a sub-tuple per row and is suggested by the error message. Additionally ,the tuple will now render with parenthesis in all contexts. Previously, the parenthesization would not render in a columns context leading to non-defined behavior. As part of this change, Tuple receives a dedicated datatype which appears to allow us the very desirable change of removing the bindparam._expanding_in_types attribute as well as ClauseList._tuple_values (which might already have not been needed due to #4645). Fixes: #5127 Change-Id: Iecafa0e0aac2f1f37ec8d0e1631d562611c90200 --- lib/sqlalchemy/engine/default.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/engine') diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 4fb20a3d5..ec0f2ed9f 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -1456,8 +1456,8 @@ class DefaultExecutionContext(interfaces.ExecutionContext): continue if key in self._expanded_parameters: - if bindparam._expanding_in_types: - num = len(bindparam._expanding_in_types) + if bindparam.type._is_tuple_type: + num = len(bindparam.type.types) dbtypes = inputsizes[bindparam] positional_inputsizes.extend( [ @@ -1488,8 +1488,8 @@ class DefaultExecutionContext(interfaces.ExecutionContext): continue if key in self._expanded_parameters: - if bindparam._expanding_in_types: - num = len(bindparam._expanding_in_types) + if bindparam.type._is_tuple_type: + num = len(bindparam.type.types) dbtypes = inputsizes[bindparam] keyword_inputsizes.update( [ -- cgit v1.2.1