summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-19 17:28:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-19 17:28:14 -0400
commitfd57a4116301c91a651e397f65235bc6a766a39d (patch)
tree2dd8f067a3e9ee1d0417aaad8e77448d41a08ea7 /lib/sqlalchemy/orm/loading.py
parent72a09d9e5c54e3ee8b3561da144d8379ce1df747 (diff)
downloadsqlalchemy-fd57a4116301c91a651e397f65235bc6a766a39d.tar.gz
Revert "remove events nobody uses...?"
This reverts commit 72a09d9e5c54e3ee8b3561da144d8379ce1df747.
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index c366d8df4..8fcace9be 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -310,6 +310,12 @@ def instance_processor(mapper, context, path, adapter,
session_identity_map = context.session.identity_map
+ listeners = mapper.dispatch
+
+ translate_row = listeners.translate_row or None
+ create_instance = listeners.create_instance or None
+ populate_instance = listeners.populate_instance or None
+ append_result = listeners.append_result or None
populate_existing = context.populate_existing or mapper.always_refresh
invoke_all_eagers = context.invoke_all_eagers
@@ -332,6 +338,13 @@ def instance_processor(mapper, context, path, adapter,
eager_populators
)
+ if translate_row:
+ for fn in translate_row:
+ ret = fn(mapper, context, row)
+ if ret is not EXT_CONTINUE:
+ row = ret
+ break
+
if polymorphic_on is not None:
discriminator = row[polymorphic_on]
if discriminator is not None:
@@ -401,7 +414,21 @@ def instance_processor(mapper, context, path, adapter,
currentload = True
loaded_instance = True
- instance = mapper.class_manager.new_instance()
+ if create_instance:
+ for fn in create_instance:
+ instance = fn(mapper, context,
+ row, mapper.class_)
+ if instance is not EXT_CONTINUE:
+ manager = attributes.manager_of_class(
+ instance.__class__)
+ # TODO: if manager is None, raise a friendly error
+ # about returning instances of unmapped types
+ manager.setup_instance(instance)
+ break
+ else:
+ instance = mapper.class_manager.new_instance()
+ else:
+ instance = mapper.class_manager.new_instance()
dict_ = instance_dict(instance)
state = instance_state(instance)
@@ -418,7 +445,17 @@ def instance_processor(mapper, context, path, adapter,
state.runid = context.runid
context.progress[state] = dict_
- populate_state(state, dict_, row, isnew, only_load_props)
+ if populate_instance:
+ for fn in populate_instance:
+ ret = fn(mapper, context, row, state,
+ only_load_props=only_load_props,
+ instancekey=identitykey, isnew=isnew)
+ if ret is not EXT_CONTINUE:
+ break
+ else:
+ populate_state(state, dict_, row, isnew, only_load_props)
+ else:
+ populate_state(state, dict_, row, isnew, only_load_props)
if loaded_instance and load_evt:
state.manager.dispatch.load(state, context)
@@ -437,7 +474,17 @@ def instance_processor(mapper, context, path, adapter,
attrs = state.unloaded
context.partials[state] = (dict_, attrs)
- populate_state(state, dict_, row, isnew, attrs)
+ if populate_instance:
+ for fn in populate_instance:
+ ret = fn(mapper, context, row, state,
+ only_load_props=attrs,
+ instancekey=identitykey, isnew=isnew)
+ if ret is not EXT_CONTINUE:
+ break
+ else:
+ populate_state(state, dict_, row, isnew, attrs)
+ else:
+ populate_state(state, dict_, row, isnew, attrs)
for key, pop in eager_populators:
if key not in state.unloaded:
@@ -447,7 +494,16 @@ def instance_processor(mapper, context, path, adapter,
state.manager.dispatch.refresh(state, context, attrs)
if result is not None:
- result.append(instance)
+ if append_result:
+ for fn in append_result:
+ if fn(mapper, context, row, state,
+ result, instancekey=identitykey,
+ isnew=isnew) is not EXT_CONTINUE:
+ break
+ else:
+ result.append(instance)
+ else:
+ result.append(instance)
return instance
return _instance