From c99fc44e170be61696206872701ff75e4c8a3711 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 8 May 2016 02:21:57 -0400 Subject: Use the "committed" values when extracting many-to-one lazyload value The scalar object set() method calls upon the lazy loader to get at the "old" value of the attriute, however doesn't ensure that the "committed" value of the foreign key attributes is used. If the user has manipulated these attributes and they themselves have pending, non committed changes, we get the "new" value which these attributes would have set up if they were flushed. "old" vs "new" value is always about how the value has changed since the load, so we always have to use the DB-persisted values for everything when looking for "old". Change-Id: I82bdc40ad0cf033c3a98f3361776cf3161542cd6 Fixes: #3708 --- lib/sqlalchemy/orm/attributes.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 7239d41f2..e01c13587 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -788,9 +788,13 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl): """ if self.dispatch._active_history: old = self.get( - state, dict_, passive=PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH) + state, dict_, + passive=PASSIVE_ONLY_PERSISTENT | + NO_AUTOFLUSH | LOAD_AGAINST_COMMITTED) else: - old = self.get(state, dict_, passive=PASSIVE_NO_FETCH ^ INIT_OK) + old = self.get( + state, dict_, passive=PASSIVE_NO_FETCH ^ INIT_OK | + LOAD_AGAINST_COMMITTED) if check_old is not None and \ old is not PASSIVE_NO_RESULT and \ -- cgit v1.2.1