summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/dynamic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-07-18 10:58:24 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-07-18 10:58:24 -0400
commit5e8c7c88de2d9bac58e82bc1e5af7fcad5405855 (patch)
tree87094ca0ac2b087a7e54133ac2babfcfb994fbb7 /lib/sqlalchemy/orm/dynamic.py
parentc01f90de584f50f036c5b6d0c44074b4b3014da4 (diff)
downloadsqlalchemy-5e8c7c88de2d9bac58e82bc1e5af7fcad5405855.tar.gz
Fixes for uselist=True with m2o relationships
Fixed bug where a many-to-one relationship that specified ``uselist=True`` would fail to update correctly during a primary key change where a related column needs to change. Fixed bug where the detection for many-to-one or one-to-one use with a "dynamic" relationship, which is an invalid configuration, would fail to raise if the relationship were configured with ``uselist=True``. The current fix is that it warns, instead of raises, as this would otherwise be backwards incompatible, however in a future release it will be a raise. Fixes: #4772 Change-Id: Ibd5d2f7329ff245c88118e2533fc8ef42a09fef3
Diffstat (limited to 'lib/sqlalchemy/orm/dynamic.py')
-rw-r--r--lib/sqlalchemy/orm/dynamic.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py
index 20544dbbe..3218b9fa3 100644
--- a/lib/sqlalchemy/orm/dynamic.py
+++ b/lib/sqlalchemy/orm/dynamic.py
@@ -14,6 +14,7 @@ basic add/delete mutation.
from . import attributes
from . import exc as orm_exc
+from . import interfaces
from . import object_mapper
from . import object_session
from . import properties
@@ -36,6 +37,17 @@ class DynaLoader(strategies.AbstractRelationshipLoader):
"many-to-one/one-to-one relationships and/or "
"uselist=False." % self.parent_property
)
+ elif self.parent_property.direction not in (
+ interfaces.ONETOMANY,
+ interfaces.MANYTOMANY,
+ ):
+ util.warn(
+ "On relationship %s, 'dynamic' loaders cannot be used with "
+ "many-to-one/one-to-one relationships and/or "
+ "uselist=False. This warning will be an exception in a "
+ "future release." % self.parent_property
+ )
+
strategies._register_attribute(
self.parent_property,
mapper,