]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
warn or deprecate for auto-aliasing in joins
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Sep 2021 16:12:46 +0000 (12:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Sep 2021 17:27:54 +0000 (13:27 -0400)
commit6ce0d644db60ce6ea89eb15a76e078c4fa1a9066
treef800bc5e1c308eae078e732c834d8eca501461cb
parent52e8545b2df312898d46f6a5b119675e8d0aa956
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
24 files changed:
doc/build/changelog/unreleased_14/6974.rst [new file with mode: 0644]
doc/build/changelog/unreleased_14/inh_cond.rst [new file with mode: 0644]
doc/build/errors.rst
doc/build/orm/queryguide.rst
doc/build/orm/self_referential.rst
lib/sqlalchemy/exc.py
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/sql/roles.py
lib/sqlalchemy/testing/assertions.py
lib/sqlalchemy/testing/fixtures.py
test/aaa_profiling/test_memusage.py
test/aaa_profiling/test_orm.py
test/orm/declarative/test_basic.py
test/orm/inheritance/test_assorted_poly.py
test/orm/inheritance/test_basic.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_froms.py
test/orm/test_joins.py
test/orm/test_mapper.py