summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-04-28 12:40:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-04-28 12:44:00 -0400
commit23a1c60982dc4799c76f0cec276a3bae8a24395b (patch)
treea5e32ecc74a8d40ae4dd8049ef955bf9dbda9b68 /lib/sqlalchemy/orm/session.py
parent2f55c844051d9fe8865576bd77107e94c6de16c1 (diff)
downloadsqlalchemy-23a1c60982dc4799c76f0cec276a3bae8a24395b.tar.gz
Warn on merge of already-pending object
A warning is now emitted for the case where a transient object is being merged into the session with :meth:`.Session.merge` when that object is already transient in the :class:`.Session`. This warns for the case where the object would normally be double-inserted. Fixes: #4647 Change-Id: Ie5223a59a2856664bf283017e962caf8c4230536
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 0b1a3b101..eccd60fe2 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -2110,6 +2110,13 @@ class Session(_SessionClassMethods):
key = state.key
if key is None:
+ if state in self._new:
+ util.warn(
+ "Instance %s is already pending in this Session yet is "
+ "being merged again; this is probably not what you want "
+ "to do" % state_str(state)
+ )
+
if not load:
raise sa_exc.InvalidRequestError(
"merge() with load=False option does not support "