diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 13 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 7 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 2dbef2497..c6c1860ea 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -883,6 +883,19 @@ class InstanceState(object): or (key in self.manager.mutable_attributes and not self.manager[key].impl.check_mutable_modified(self)) ]) unmodified = property(unmodified) + + def unloaded(self): + """a set of keys which do not have a loaded value. + + This includes expired attributes and any other attribute that + was never populated or modified. + + """ + return util.Set([ + key for key in self.manager.keys() if + key not in self.committed_state and key not in self.dict + ]) + unloaded = property(unloaded) def expire_attributes(self, attribute_names): self.expired_attributes = util.Set(self.expired_attributes) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index dd54ed986..da471b4d1 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1473,16 +1473,15 @@ class Mapper(object): else: # populate attributes on non-loading instances which have been expired - # TODO: also support deferred attributes here [ticket:870] # TODO: apply eager loads to un-lazy loaded collections ? - # we might want to create an expanded form of 'state.expired_attributes' which includes deferred/un-lazy loaded - if state.expired_attributes: + if state in context.partials or state.unloaded: + if state in context.partials: isnew = False attrs = context.partials[state] else: isnew = True - attrs = state.expired_attributes.intersection(state.unmodified) + attrs = state.unloaded context.partials[state] = attrs #<-- allow query.instances to commit the subset of attrs if not populate_instance or extension.populate_instance(self, context, row, instance, only_load_props=attrs, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE: |
