summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/automap.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-06-25 16:51:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-06-25 16:53:01 -0400
commit65e16e9b3e9ceabfbf3f11fbefa498109d8b335a (patch)
tree66211cf6d11ce2f84ac982871d0bdb53f003b656 /lib/sqlalchemy/ext/automap.py
parent791f1d9407f68cc668c7078fa87784ebdf3bd688 (diff)
downloadsqlalchemy-65e16e9b3e9ceabfbf3f11fbefa498109d8b335a.tar.gz
have automap suppress overlaps warning for mapped secondary
Fixed regression in :mod:`sqlalchemy.ext.automap` extension such that the use case of creating an explicit mapped class to a table that is also the :paramref:`_orm.relationship.secondary` element of a :func:`_orm.relationship` that automap will be generating would emit the "overlaps" warnings introduced in 1.4 and discussed at :ref:`error_qzyx`. While generating this case from automap is still subject to the same caveats that the "overlaps" warning refers towards, as automap is intended for more ad-hoc use cases, the condition which produces the warning is disabled when a many-to-many relationship with this particular pattern is generated. Fixes: #6679 Change-Id: Ib3a53982b076ed4999b0d3235f84008b9e2f1cce
Diffstat (limited to 'lib/sqlalchemy/ext/automap.py')
-rw-r--r--lib/sqlalchemy/ext/automap.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/automap.py b/lib/sqlalchemy/ext/automap.py
index e20435911..8b75dce7b 100644
--- a/lib/sqlalchemy/ext/automap.py
+++ b/lib/sqlalchemy/ext/automap.py
@@ -1153,6 +1153,11 @@ def _m2m_relationship(
create_backref = backref_name not in referred_cfg.properties
+ if table in table_to_map_config:
+ overlaps = "__*"
+ else:
+ overlaps = None
+
if relationship_name not in map_config.properties:
if create_backref:
backref_obj = generate_relationship(
@@ -1163,9 +1168,11 @@ def _m2m_relationship(
referred_cls,
local_cls,
collection_class=collection_class,
+ overlaps=overlaps,
)
else:
backref_obj = None
+
rel = generate_relationship(
automap_base,
interfaces.MANYTOMANY,
@@ -1173,6 +1180,7 @@ def _m2m_relationship(
relationship_name,
local_cls,
referred_cls,
+ overlaps=overlaps,
secondary=table,
primaryjoin=and_(
fk.column == fk.parent for fk in m2m_const[0].elements
@@ -1198,6 +1206,7 @@ def _m2m_relationship(
backref_name,
referred_cls,
local_cls,
+ overlaps=overlaps,
secondary=table,
primaryjoin=and_(
fk.column == fk.parent for fk in m2m_const[1].elements