From: Mike Bayer Date: Fri, 21 Dec 2007 07:26:39 +0000 (+0000) Subject: mass load wont overwrite modified expired attributes X-Git-Tag: rel_0_4_2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9dd765d921a01efce811c689a0ec06b90ccbc5d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git mass load wont overwrite modified expired attributes --- diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 135269906b..f18e54521f 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -766,7 +766,7 @@ class InstanceState(object): serializable. """ instance = self.obj() - self.class_._class_state.deferred_scalar_loader(instance, [k for k in self.expired_attributes if k not in self.committed_state]) + self.class_._class_state.deferred_scalar_loader(instance, [k for k in self.expired_attributes if k in self.unmodified]) for k in self.expired_attributes: self.callables.pop(k, None) self.expired_attributes.clear() diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index db666a4f99..f61b70bc3c 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1367,8 +1367,11 @@ class Mapper(object): self.populate_instance(context, instance, row, only_load_props=only_load_props, instancekey=identitykey, isnew=isnew) elif getattr(state, 'expired_attributes', None): - if 'populate_instance' not in extension.methods or extension.populate_instance(self, context, row, instance, only_load_props=state.expired_attributes, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE: - self.populate_instance(context, instance, row, only_load_props=state.expired_attributes, instancekey=identitykey, isnew=isnew) + # TODO: dont base this off of 'expired_attrbutes' - base it off of unloaded attrs, possibly + # based on the state.callables collection. + attrs = state.expired_attributes.intersection(state.unmodified) + if 'populate_instance' not in extension.methods or extension.populate_instance(self, context, row, instance, only_load_props=attrs, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE: + self.populate_instance(context, instance, row, only_load_props=attrs, instancekey=identitykey, isnew=isnew) if result is not None and ('append_result' not in extension.methods or extension.append_result(self, context, row, instance, result, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE): result.append(instance) diff --git a/test/orm/expire.py b/test/orm/expire.py index e1c0166120..1b6e0affd1 100644 --- a/test/orm/expire.py +++ b/test/orm/expire.py @@ -84,6 +84,20 @@ class ExpireTest(FixtureTest): assert o.description is None + o.isopen=15 + sess.expire(o, ['isopen', 'description']) + o.description = 'some new description' + sess.query(Order).all() + assert o.isopen == 1 + assert o.description == 'some new description' + + sess.expire(o, ['isopen', 'description']) + sess.query(Order).all() + del o.isopen + def go(): + assert o.isopen is None + self.assert_sql_count(testbase.db, go, 0) + def test_expire_committed(self): """test that the committed state of the attribute receives the most recent DB data""" mapper(Order, orders)