diff options
| author | Gord Thompson <gord@gordthompson.com> | 2021-01-09 14:56:38 -0700 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-26 16:52:30 -0500 |
| commit | 22f65156bbe846dea2fb9f87fe4187abe0ed790a (patch) | |
| tree | f49338a10dd2800d4d754b14d2e7fd549b4b833f /test/sql/test_functions.py | |
| parent | 7bdb1f30f66aaea16efbcf96e314491058493e6c (diff) | |
| download | sqlalchemy-22f65156bbe846dea2fb9f87fe4187abe0ed790a.tar.gz | |
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
Diffstat (limited to 'test/sql/test_functions.py')
| -rw-r--r-- | test/sql/test_functions.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index 50f50f0f0..19562dade 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -28,6 +28,7 @@ from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import sqlite from sqlalchemy.sql import column from sqlalchemy.sql import functions +from sqlalchemy.sql import LABEL_STYLE_TABLENAME_PLUS_COL from sqlalchemy.sql import quoted_name from sqlalchemy.sql import table from sqlalchemy.sql.compiler import BIND_TEMPLATES @@ -95,7 +96,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_use_labels(self): self.assert_compile( - select(func.foo()).apply_labels(), "SELECT foo() AS foo_1" + select(func.foo()).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL), + "SELECT foo() AS foo_1", ) def test_use_labels_function_element(self): @@ -109,7 +111,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): return "max(%s)" % compiler.process(element.clauses, **kw) self.assert_compile( - select(max_(5, 6)).apply_labels(), + select(max_(5, 6)).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL), "SELECT max(:max_2, :max_3) AS max_1", ) |
