def new_instance(self, state=None):
instance = self.class_.__new__(self.class_)
setattr(instance, self.STATE_ATTR,
- state or self._state_constructor(instance, self))
+ self._state_constructor(instance, self)
+ if not state else state)
return instance
def setup_instance(self, instance, state=None):
setattr(instance, self.STATE_ATTR,
- state or self._state_constructor(instance, self))
+ self._state_constructor(instance, self)
+ if not state else state)
def teardown_instance(self, instance):
delattr(instance, self.STATE_ATTR)
append_result = listeners.append_result or None
populate_existing = context.populate_existing or mapper.always_refresh
invoke_all_eagers = context.invoke_all_eagers
-
load_evt = mapper.class_manager.dispatch.load or None
refresh_evt = mapper.class_manager.dispatch.refresh or None
-
instance_state = attributes.instance_state
instance_dict = attributes.instance_dict
_populators(mapper, context, path, row, adapter,
new_populators,
existing_populators,
- eager_populators
- )
+ eager_populators)
if translate_row:
for fn in translate_row:
if key not in state.unloaded:
pop(state, dict_, row)
- if isnew:
+ if isnew and refresh_evt:
state.manager.dispatch.refresh(state, context, attrs)
if result is not None:
expired = False
deleted = False
_load_pending = False
+ committed_state = util.immutabledict()
+ callables = util.immutabledict()
is_instance = True
self.class_ = obj.__class__
self.manager = manager
self.obj = weakref.ref(obj, self._cleanup)
- self.callables = {}
- self.committed_state = {}
+
+ @util.memoized_property
+ def callables(self):
+ return {}
+
+ @util.memoized_property
+ def committed_state(self):
+ return {}
@util.memoized_property
def attrs(self):
if instance_dict:
instance_dict.discard(self)
- self.callables = {}
+ if 'callables' in self.__dict__:
+ del self.callables
self.session_id = self._strong_obj = None
del self.obj
@classmethod
def _commit_all_states(self, iter, instance_dict=None):
- """Mass version of commit_all()."""
+ """Mass / highly inlined version of commit_all()."""
for state, dict_ in iter:
- state.committed_state.clear()
+ state_dict = state.__dict__
+
+ if 'committed_state' in state_dict:
+ del state_dict['committed_state']
- # inline of:
- # InstanceState._pending_mutations._reset(state)
- state.__dict__.pop('_pending_mutations', None)
+ if '_pending_mutations' in state_dict:
+ del state_dict['_pending_mutations']
- callables = state.callables
- if callables:
+ if 'callables' in state_dict:
+ callables = state.callables
for key in list(callables):
if key in dict_ and callables[key] is state:
del callables[key]