]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Check explicitly for mapped class as secondary
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Dec 2020 14:45:48 +0000 (09:45 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Dec 2020 15:50:29 +0000 (10:50 -0500)
commite5ce965d070c11d84eeb30247722d8ff5e03c411
treee8f3dc76c91eb01b3fe9e30ec900ad2c29f4fc84
parent236bf7b5f118a6f34d8e56c4ebc5897e0a276b29
Check explicitly for mapped class as secondary

Added a comprehensive check and an informative error message for the case
where a mapped class, or a string mapped class name, is passed to
:paramref:`_orm.relationship.secondary`.  This is an extremely common error
which warrants a clear message.

Additionally, added a new rule to the class registry resolution such that
with regards to the :paramref:`_orm.relationship.secondary` parameter, if a
mapped class and its table are of the identical string name, the
:class:`.Table` will be favored when resolving this parameter.   In all
other cases, the class continues to be favored if a class and table
share the identical name.

Fixes: #5774
Change-Id: I65069d79c1c3897fbd1081a8e1edf3b63b497223
(cherry picked from commit cfcfb7d43c2719ef6e4901dca43de5b492a1f08f)
doc/build/changelog/unreleased_13/5774.rst [new file with mode: 0644]
lib/sqlalchemy/ext/declarative/clsregistry.py
lib/sqlalchemy/orm/relationships.py
test/ext/declarative/test_basic.py
test/orm/test_relationships.py