summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/assertions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-03-29 14:24:39 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-03-29 22:27:41 -0400
commita65d5c250e9fd7090311ef12f28d7d959c6c738e (patch)
tree349f0b4c1127c3d87d9cffb62b5d6e02979a3a9a /lib/sqlalchemy/testing/assertions.py
parent8e857e3f6beecf7510f741428d8d0ba24f5cb71b (diff)
downloadsqlalchemy-a65d5c250e9fd7090311ef12f28d7d959c6c738e.tar.gz
Add a third labeling mode for SELECT statements
Enhanced the disambiguating labels feature of the :func:`~.sql.expression.select` construct such that when a select statement is used in a subquery, repeated column names from different tables are now automatically labeled with a unique label name, without the need to use the full "apply_labels()" feature that conbines tablename plus column name. The disambigated labels are available as plain string keys in the .c collection of the subquery, and most importantly the feature allows an ORM :func:`.orm.aliased` construct against the combination of an entity and an arbitrary subquery to work correctly, targeting the correct columns despite same-named columns in the source tables, without the need for an "apply labels" warning. The existing labeling style is now called LABEL_STYLE_TABLENAME_PLUS_COL. This labeling style will remain used throughout the ORM as has been the case for over a decade, however, the new disambiguation scheme could theoretically replace this scheme entirely. The new scheme would dramatically alter how SQL looks when rendered from the ORM to be more succinct but arguably harder to read. The tablename_columnname scheme used by Join.c is unaffected here, as that's still hardcoded to that scheme. Fixes: #5221 Change-Id: Ib47d9e0f35046b3afc77bef6e65709b93d0c3026
Diffstat (limited to 'lib/sqlalchemy/testing/assertions.py')
-rw-r--r--lib/sqlalchemy/testing/assertions.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 7dada1394..5af29a723 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -24,6 +24,7 @@ from .. import types as sqltypes
from .. import util
from ..engine import default
from ..engine import url
+from ..sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from ..util import compat
from ..util import decorator
@@ -398,7 +399,7 @@ class AssertsCompiledSQL(object):
if isinstance(clause, orm.Query):
context = clause._compile_context()
- context.statement.use_labels = True
+ context.statement._label_style = LABEL_STYLE_TABLENAME_PLUS_COL
clause = context.statement
elif isinstance(clause, orm.persistence.BulkUD):
with mock.patch.object(clause, "_execute_stmt") as stmt_mock: