]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- when attributes are expired on a pending instance, an
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 01:52:36 +0000 (01:52 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 01:52:36 +0000 (01:52 +0000)
error will not be raised when the "refresh" action
is triggered and returns no result

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/expire.py

diff --git a/CHANGES b/CHANGES
index 2c83be0cc2f9e1f4387bedef21ae47eea384e99f..2c9120be5bd0fe24fbd7c2ec1f00f54ecf5ecba4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,11 @@ CHANGES
 
 0.4.5
 =====
-
+- orm
+    - when attributes are expired on a pending instance, an 
+      error will not be raised when the "refresh" action 
+      is triggered and returns no result
+    
 0.4.4
 ------
 - sql
index ae48f9e55f8d7a8cf8c5433d159fd2b2933f0b97..b7ed313950f0b3f2085775bb2ab9cefbc6a63506 100644 (file)
@@ -1565,10 +1565,13 @@ def _load_scalar_attributes(instance, attribute_names):
     state = instance._state
     if '_instance_key' in state.dict:
         identity_key = state.dict['_instance_key']
+        shouldraise = True
     else:
+        # if instance is pending, a refresh operation may not complete (even if PK attributes are assigned)
+        shouldraise = False
         identity_key = mapper._identity_key_from_state(state)
 
-    if session.query(mapper)._get(identity_key, refresh_instance=state, only_load_props=attribute_names) is None:
+    if session.query(mapper)._get(identity_key, refresh_instance=state, only_load_props=attribute_names) is None and shouldraise:
         raise exceptions.InvalidRequestError("Could not refresh instance '%s'" % instance_str(instance))
 
 def _state_mapper(state, entity_name=None):
index 8d622dd0cdbadf8a7523a23e544d6203802967f6..58c05a3820eaeae0f3a638e0740895015c9b9418 100644 (file)
@@ -84,6 +84,14 @@ class ExpireTest(FixtureTest):
         except exceptions.InvalidRequestError, e:
             assert str(e) == "Instance <class 'testlib.fixtures.User'> is not bound to a Session, and no contextual session is established; attribute refresh operation cannot proceed"
     
+    def test_pending_doesnt_raise(self):
+        mapper(User, users)
+        sess = create_session()
+        u = User(id=15)
+        sess.save(u)
+        sess.expire(u, ['name'])
+        assert u.name is None
+        
     def test_no_instance_key(self):
         # this tests an artificial condition such that 
         # an instance is pending, but has expired attributes.  this