]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Replace with_labels() and apply_labels() in ORM/Core
authorGord Thompson <gord@gordthompson.com>
Sat, 9 Jan 2021 21:56:38 +0000 (14:56 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 Jan 2021 21:52:30 +0000 (16:52 -0500)
commit22f65156bbe846dea2fb9f87fe4187abe0ed790a
treef49338a10dd2800d4d754b14d2e7fd549b4b833f
parent7bdb1f30f66aaea16efbcf96e314491058493e6c
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 <mike_mp@zzzcomputing.com>
Fixes: #4757
Change-Id: I5fdcd2ed4ae8c7fe62f8be2b6d0e8f66409b6a54
51 files changed:
doc/build/changelog/unreleased_14/4757.rst [new file with mode: 0644]
doc/build/core/selectable.rst
doc/build/core/tutorial.rst
doc/build/tutorial/data.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/persistence.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/sql/__init__.py
lib/sqlalchemy/sql/coercions.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/sql/selectable.py
test/aaa_profiling/test_compiler.py
test/dialect/mssql/test_compiler.py
test/dialect/mssql/test_deprecations.py
test/dialect/oracle/test_compiler.py
test/dialect/postgresql/test_compiler.py
test/dialect/postgresql/test_dialect.py
test/orm/inheritance/_poly_fixtures.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_concrete.py
test/orm/inheritance/test_poly_loading.py
test/orm/inheritance/test_polymorphic_rel.py
test/orm/inheritance/test_relationship.py
test/orm/inheritance/test_single.py
test/orm/test_deprecations.py
test/orm/test_eager_relations.py
test/orm/test_froms.py
test/orm/test_joins.py
test/orm/test_lambdas.py
test/orm/test_lazy_relations.py
test/orm/test_query.py
test/profiles.txt
test/sql/test_compare.py
test/sql/test_compiler.py
test/sql/test_cte.py
test/sql/test_deprecations.py
test/sql/test_external_traversal.py
test/sql/test_functions.py
test/sql/test_labels.py
test/sql/test_operators.py
test/sql/test_query.py
test/sql/test_quote.py
test/sql/test_resultset.py
test/sql/test_selectable.py
test/sql/test_text.py
test/sql/test_type_expressions.py