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/dialect/postgresql/test_compiler.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/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index b2c7ce1c2..8c8a84c4e 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1551,13 +1551,15 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): stmt = select(tbl1, tbl2).with_hint(tbl1, "ONLY", "postgresql") expected = ( - "SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, " "testtbl2" + "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, " + "testtbl2" ) self.assert_compile(stmt, expected) stmt = select(tbl1, tbl2).with_hint(tbl2, "ONLY", "postgresql") expected = ( - "SELECT testtbl1.id, testtbl2.id FROM testtbl1, ONLY " "testtbl2" + "SELECT testtbl1.id, testtbl2.id AS id_1 FROM testtbl1, ONLY " + "testtbl2" ) self.assert_compile(stmt, expected) @@ -1565,7 +1567,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): stmt = stmt.with_hint(tbl1, "ONLY", "postgresql") stmt = stmt.with_hint(tbl2, "ONLY", "postgresql") expected = ( - "SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, " + "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, " "ONLY testtbl2" ) self.assert_compile(stmt, expected) @@ -2387,7 +2389,7 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( q, - "SELECT DISTINCT ON (anon_1.id) t.id, anon_1.id " + "SELECT DISTINCT ON (anon_1.id) t.id, anon_1.id AS id_1 " "FROM t, (SELECT t.id AS id, t.a AS a, t.b " "AS b FROM t) AS anon_1 WHERE t.id = anon_1.id", ) @@ -2401,7 +2403,7 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( q, - "SELECT DISTINCT ON (sq.id) t.id, sq.id " + "SELECT DISTINCT ON (sq.id) t.id, sq.id AS id_1 " "FROM t, (SELECT t.id AS id, t.a AS a, " "t.b AS b FROM t) AS sq WHERE t.id = sq.id", ) |