diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-04 12:12:46 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-28 13:27:54 -0400 |
| commit | 6ce0d644db60ce6ea89eb15a76e078c4fa1a9066 (patch) | |
| tree | f800bc5e1c308eae078e732c834d8eca501461cb /test/aaa_profiling | |
| parent | 52e8545b2df312898d46f6a5b119675e8d0aa956 (diff) | |
| download | sqlalchemy-6ce0d644db60ce6ea89eb15a76e078c4fa1a9066.tar.gz | |
warn or deprecate for auto-aliasing in joins
An extra layer of warning messages has been added to the functionality
of :meth:`_orm.Query.join` and the ORM version of
:meth:`_sql.Select.join`, where a few places where "automatic aliasing"
continues to occur will now be called out as a pattern to avoid, mostly
specific to the area of joined table inheritance where classes that share
common base tables are being joined together without using explicit aliases.
One case emits a legacy warning for a pattern that's not recommended,
the other case is fully deprecated.
The automatic aliasing within ORM join() which occurs for overlapping
mapped tables does not work consistently with all APIs such as
``contains_eager()``, and rather than continue to try to make these use
cases work everywhere, replacing with a more user-explicit pattern
is clearer, less prone to bugs and simplifies SQLAlchemy's internals
further.
The warnings include links to the errors.rst page where each pattern is
demonstrated along with the recommended pattern to fix.
* Improved the exception message generated when configuring a mapping with
joined table inheritance where the two tables either have no foreign key
relationships set up, or where they have multiple foreign key relationships
set up. The message is now ORM specific and includes context that the
:paramref:`_orm.Mapper.inherit_condition` parameter may be needed
particularly for the ambiguous foreign keys case.
* Add explicit support in the _expect_warnings() assertion for nested
_expect_warnings calls
* generalize the NoCache fixture, which we also need to catch warnings
during compilation consistently
* generalize the __str__() method for the HasCode mixin so all warnings
and errors include the code link in their string
Fixes: #6974
Change-Id: I84ed79ba2112c39eaab7973b6d6f46de7fa80842
Diffstat (limited to 'test/aaa_profiling')
| -rw-r--r-- | test/aaa_profiling/test_memusage.py | 2 | ||||
| -rw-r--r-- | test/aaa_profiling/test_orm.py | 15 |
2 files changed, 2 insertions, 15 deletions
diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index 6462ab9f1..1c08c30a2 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -1141,7 +1141,7 @@ class MemUsageWBackendTest(EnsureZeroed): @profile_memory() def go(): - s = table2.select().subquery() + s = aliased(Bar, table2.select().subquery()) sess = session() sess.query(Foo).join(s, Foo.bars).all() sess.rollback() diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py index 7de1811ae..727d48fca 100644 --- a/test/aaa_profiling/test_orm.py +++ b/test/aaa_profiling/test_orm.py @@ -18,27 +18,14 @@ from sqlalchemy.orm import relationship from sqlalchemy.orm import selectinload from sqlalchemy.orm import Session from sqlalchemy.orm import sessionmaker -from sqlalchemy.testing import config from sqlalchemy.testing import fixtures from sqlalchemy.testing import profiling from sqlalchemy.testing.fixtures import fixture_session +from sqlalchemy.testing.fixtures import NoCache from sqlalchemy.testing.schema import Column from sqlalchemy.testing.schema import Table -class NoCache(object): - run_setup_bind = "each" - - @classmethod - def setup_test_class(cls): - cls._cache = config.db._compiled_cache - config.db._compiled_cache = None - - @classmethod - def teardown_test_class(cls): - config.db._compiled_cache = cls._cache - - class MergeTest(NoCache, fixtures.MappedTest): __requires__ = ("python_profiling_backend",) |
