Anonymous avatar Anonymous committed c78e8ff

- use easy to recognize names for backref events [ticket:2066]

Comments (0)

Files changed (1)

lib/sqlalchemy/orm/attributes.py

 def backref_listeners(attribute, key, uselist):
     """Apply listeners to synchronize a two-way relationship."""
 
-    def set_(state, child, oldchild, initiator):
+    # use easily recognizable names for stack traces
+
+    def emit_backref_from_scalar_set_event(state, child, oldchild, initiator):
         if oldchild is child:
             return child
 
                                             passive=PASSIVE_NO_FETCH)
         return child
 
-    def append(state, child, initiator):
+    def emit_backref_from_collection_append_event(state, child, initiator):
         child_state, child_dict = instance_state(child), \
                                     instance_dict(child)
         child_state.manager[key].impl.append(
                                             passive=PASSIVE_NO_FETCH)
         return child
 
-    def remove(state, child, initiator):
+    def emit_backref_from_collection_remove_event(state, child, initiator):
         if child is not None:
             child_state, child_dict = instance_state(child),\
                                         instance_dict(child)
                                             passive=PASSIVE_NO_FETCH)
 
     if uselist:
-        event.listen(attribute, "append", append, retval=True, raw=True)
+        event.listen(attribute, "append", 
+                    emit_backref_from_collection_append_event, 
+                    retval=True, raw=True)
     else:
-        event.listen(attribute, "set", set_, retval=True, raw=True)
+        event.listen(attribute, "set", 
+                    emit_backref_from_scalar_set_event, 
+                    retval=True, raw=True)
     # TODO: need coverage in test/orm/ of remove event
-    event.listen(attribute, "remove", remove, retval=True, raw=True)
+    event.listen(attribute, "remove", 
+                    emit_backref_from_collection_remove_event, 
+                    retval=True, raw=True)
 
 class History(tuple):
     """A 3-tuple of added, unchanged and deleted values,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.