From 90c3944dacad5c1ebb023d6fa2abb95d8ac0dda4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 21 Dec 2007 16:20:46 +0000 Subject: [PATCH] - disabled the "populate expired/deferred attributes as we come across them" functionality in mapper._instance(), as its not completed, doesn't properly handle mutable scalar attributes, and has poor test coverage --- lib/sqlalchemy/orm/mapper.py | 14 ++++++-------- test/orm/expire.py | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index f61b70bc3c..6d8d88cbae 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1366,12 +1366,12 @@ class Mapper(object): if 'populate_instance' not in extension.methods or extension.populate_instance(self, context, row, instance, only_load_props=only_load_props, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE: self.populate_instance(context, instance, row, only_load_props=only_load_props, instancekey=identitykey, isnew=isnew) - elif getattr(state, 'expired_attributes', None): - # 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) +# NOTYET: populate attributes on non-loading instances which have been expired, deferred, etc. +# elif getattr(state, 'expired_attributes', None): # TODO: base off total set of unloaded attributes, not just exp +# 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) +# context.partials.add((state, attrs)) <-- allow query.instances to commit the subset of attrs 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) @@ -1412,8 +1412,6 @@ class Mapper(object): existing_populators = [] post_processors = [] for prop in self.__props.values(): - if only_load_props and prop.key not in only_load_props: - continue (newpop, existingpop, post_proc) = selectcontext.exec_with_path(self, prop.key, prop.create_row_processor, selectcontext, self, row) if newpop is not None: new_populators.append((prop.key, newpop)) diff --git a/test/orm/expire.py b/test/orm/expire.py index 1b6e0affd1..2b25c5ba93 100644 --- a/test/orm/expire.py +++ b/test/orm/expire.py @@ -38,14 +38,17 @@ class ExpireTest(FixtureTest): sess.expire(u) # object isnt refreshed yet, using dict to bypass trigger assert u.__dict__.get('name') != 'jack' - # reload all - sess.query(User).all() - # test that it refreshed - assert u.__dict__['name'] == 'jack' - def go(): - assert u.name == 'jack' - self.assert_sql_count(testbase.db, go, 0) + if False: + # NOTYET: need to implement unconditional population + # of expired attriutes in mapper._instances() + sess.query(User).all() + # test that it refreshed + assert u.__dict__['name'] == 'jack' + + def go(): + assert u.name == 'jack' + self.assert_sql_count(testbase.db, go, 0) def test_expire_doesntload_on_set(self): mapper(User, users) @@ -91,12 +94,15 @@ class ExpireTest(FixtureTest): 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) + if False: + # NOTYET: need to implement unconditional population + # of expired attriutes in mapper._instances() + 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""" -- 2.47.3