Hello. I have a naive system that links dict-like objects to mapped classes so that rows can be saved to the db. It doesn't know anything about mapped class instances, so many-to-many relationships are [currently] saved by a class mapped to the swing table itself; for example, it's the equivalent of :
client_role = Role(role_name="client") acme = Organization( organization_name="Acme") acme_is_a_client = OrganizationRoles( organization_id = acme.id, role_id = client_role.id) The deletion process iters through from child to parent according to foreign keys and performs : session.delete(acme_is_a_client) session.delete(acme) session.delete(client_role) However, if somewhere in the app "Organization.query().join('roles').select()" was performed, then deleting acme will fail because it would have been deleted automatically by session.delete(acme_is_a_client). Specifically, I get a ConcurrentModificationError saying the deleted row count was 0. Given the limitation of this approach and not trying to depend on the configuration of ondelete/passive_deletes, is it possible to simply detect whether or not acme or client_role has been deleted in the session before deleting? That is, something more like : if not object_was_deleted(session, acme_is_a_client): session.delete(acme_is_a_client) if not object_was_deleted(session, acme): # this should not be executed session.delete(acme) if not object_was_deleted(session, client_role): # nor this session.delete(client_role) The implementation below seems to detect deletions of the same object but *not* the above scenario where the objects deleted were children : def object_was_deleted(session, obj): from sqlalchemy.orm.mapper import object_mapper for c in [obj] + list(object_mapper(obj).cascade_iterator( 'delete', obj)): if c in session.uow.deleted: return True elif not session.uow._is_valid(c): return True return False Is there a way to detect deleted children? Thanks for reading and let me know if you need a more concrete example -Kumar --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---