From 22f65156bbe846dea2fb9f87fe4187abe0ed790a Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Sat, 9 Jan 2021 14:56:38 -0700 Subject: Replace with_labels() and apply_labels() in ORM/Core Replace :meth:`_orm.Query.with_labels` and :meth:`_sql.GenerativeSelect.apply_labels` with explicit getters and setters ``get_label_style`` and ``set_label_style`` to accommodate the three supported label styles: ``LABEL_STYLE_DISAMBIGUATE_ONLY`` (default), ``LABEL_STYLE_TABLENAME_PLUS_COL``, and ``LABEL_STYLE_NONE``. In addition, for Core and "future style" ORM queries, ``LABEL_STYLE_DISAMBIGUATE_ONLY`` is now the default label style. This style differs from the existing "no labels" style in that labeling is applied in the case of column name conflicts; with ``LABEL_STYLE_NONE``, a duplicate column name is not accessible via name in any case. For legacy ORM queries using :class:`_query.Query`, the table-plus-column names labeling style applied by ``LABEL_STYLE_TABLENAME_PLUS_COL`` continues to be used so that existing test suites and logging facilities see no change in behavior by default, however this style of labeling is no longer required for SQLAlchemy queries to function, as result sets are commonly matched to columns using a positional approach since SQLAlchemy 1.0. Within test suites, all use of apply_labels() / use_labels now uses the new methods. New tests added to test/sql/test_deprecations.py nad test/orm/test_deprecations.py to cover just the old apply_labels() method call. Tests in ORM that made explicit use apply_labels()/ etc. where it isn't needed for the ORM to work correctly use default label style now. Co-authored-by: Mike Bayer Fixes: #4757 Change-Id: I5fdcd2ed4ae8c7fe62f8be2b6d0e8f66409b6a54 --- lib/sqlalchemy/sql/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/sqlalchemy/sql/__init__.py') diff --git a/lib/sqlalchemy/sql/__init__.py b/lib/sqlalchemy/sql/__init__.py index 11795c3b2..7ee0bd8f4 100644 --- a/lib/sqlalchemy/sql/__init__.py +++ b/lib/sqlalchemy/sql/__init__.py @@ -47,6 +47,10 @@ from .expression import intersect_all # noqa from .expression import Join # noqa from .expression import join # noqa from .expression import label # noqa +from .expression import LABEL_STYLE_DEFAULT # noqa +from .expression import LABEL_STYLE_DISAMBIGUATE_ONLY # noqa +from .expression import LABEL_STYLE_NONE # noqa +from .expression import LABEL_STYLE_TABLENAME_PLUS_COL # noqa from .expression import lambda_stmt # noqa from .expression import LambdaElement # noqa from .expression import lateral # noqa -- cgit v1.2.1