I'm trying to provide functionality in a session extension for an
class to provide a 'before_flush' method that allows the class to make
changes to the session, and add additional items. To do this I need to
get the list of instances to be flushed to the database, and the order
in which sqlalchemy would commit the changes to the database. I then
reverse the order of this list so that items that the instances are
processed in the reverse order of the database commits. I used to do
this using some of the internal task functionality of UOW(see below),
but that is no longer available in 0.6.0. Any suggestions?
# from UOW
while True:
ret = False
for task in uow.tasks.values():
for up in list(task.dependencies):
if up.preexecute(uow):
ret = True
if not ret:
break
# HACK we are using a hidden method of UOW here
# run our tasks in reverse order this will
# cause child flushes to be called before
# parent ones
tasks = uow._sort_dependencies()
tasks.reverse()
reprocess = False
for task in tasks :
for element in task.elements :
obj_instance = element.state.obj()
if hasattr(obj_instance, 'before_flush')
and \
callable(obj_instance.before_flush) and \
not obj_instance in
self.before_items_processed :
reprocess = \
obj_instance.before_flush() or
reprocess and True or False
self.before_items_processed.append(obj_instance)
if reprocess :
self._before_flush_inner(session, instances_in)
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.