]> 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 16:24:05 +0000 (11:24 -0500)
commit09fac89debfbdcccbf2bcc433f7bec7921cf62be
treeb3b5b0c4f0e0e38e0914c8dd68086f226fcfd632
parente8ff0af840eb7fae11ef9234ae2bf1e16a9b634e
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
doc/build/changelog/unreleased_13/5774.rst [new file with mode: 0644]
lib/sqlalchemy/orm/clsregistry.py
lib/sqlalchemy/orm/relationships.py
test/orm/declarative/test_basic.py
test/orm/test_relationships.py