From 17072f8b04c6a3a989673e85ace163620f9130cd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 22 Apr 2021 10:45:01 -0400 Subject: omit text from selected_columns; clear memoizations Fixed regression where usage of the :func:`_sql.text` construct inside the columns clause of a :class:`_sql.Select` construct, which is better handled by using a :func:`_sql.literal_column` construct, would nonetheless prevent constructs like :func:`_sql.union` from working correctly. Other use cases, such as constructing subuqeries, continue to work the same as in prior versions where the :func:`_sql.text` construct is silently omitted from the collection of exported columns. Also repairs similar use within the ORM. This adds a new internal method _all_selected_columns. The existing "selected_columns" collection can't store a TextClause and this never worked, so they are omitted. The TextClause is also not "exported", i.e. available for SELECT from a subquery, as was already the case in 1.3, so the "exported_columns" and "exported_columns_iterator" accessors are where we now omit TextClause. Fixed regression involving legacy methods such as :meth:`_sql.Select.append_column` where internal assertions would fail. Fixes: #6343 Fixes: #6261 Change-Id: I7c2e5b9ae5d94131c77599a020f4310dcf812bcf --- lib/sqlalchemy/testing/__init__.py | 1 + lib/sqlalchemy/testing/schema.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/__init__.py b/lib/sqlalchemy/testing/__init__.py index a3ce24226..a311efa74 100644 --- a/lib/sqlalchemy/testing/__init__.py +++ b/lib/sqlalchemy/testing/__init__.py @@ -60,6 +60,7 @@ from .exclusions import only_if from .exclusions import only_on from .exclusions import skip from .exclusions import skip_if +from .schema import eq_clause_element from .schema import eq_type_affinity from .util import adict from .util import fail diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py index fee021cff..ede3702e5 100644 --- a/lib/sqlalchemy/testing/schema.py +++ b/lib/sqlalchemy/testing/schema.py @@ -156,6 +156,19 @@ class eq_type_affinity(object): return self.target._type_affinity is not other._type_affinity +class eq_clause_element(object): + """Helper to compare SQL structures based on compare()""" + + def __init__(self, target): + self.target = target + + def __eq__(self, other): + return self.target.compare(other) + + def __ne__(self, other): + return not self.target.compare(other) + + def _truncate_name(dialect, name): if len(name) > dialect.max_identifier_length: return ( -- cgit v1.2.1