]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Revert "remove events nobody uses...?"
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 May 2014 21:28:14 +0000 (17:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 May 2014 21:28:14 +0000 (17:28 -0400)
This reverts commit 72a09d9e5c54e3ee8b3561da144d8379ce1df747.

lib/sqlalchemy/orm/loading.py

index c366d8df43aee7e947265980acd2ad001c37914e..8fcace9be1226a77aba20c93222cd3291ee05a40 100644 (file)
@@ -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