On Sep 27, 2008, at 9:35 PM, Andy Davidoff wrote: > > I have a MySQL table structure in which an apple relates to many > oranges, which relate to many bananas. DELETE an apple, and oranges > and bananas are DELETED via cascade. > > I'm seeing a successful DELETE of a single orange followed by a SELECT > of the orange's related bananas and then a second attempt to delete > the orange. This results in a "ConcurrentModificationError: Deleted > rowcount 0 does not match number of objects deleted 1" because the > orange has already been deleted. > > Since I haven't tracked trunk for awhile, this too could be the result > of my own ignorance. The following code works in 5057 and fails in > 5058. Any hints are much appreciated! > > > while apple.orangesrelation: > session.delete(apple.orangesrelation.pop()) > > > Revision log for 5058 follows SQL log below: > > > DELETE FROM orange WHERE orange.orange_id = %s > [1482049L] > SELECT ... FROM banana WHERE %s = banana.orange_id > [1482049L] > DELETE FROM orange WHERE orange.orange_id = %s > [1482049L] > ROLLBACK
I dont really see how you could get this exact SQL out of the session, since its literally attempting to delete the same orange object twice, which should be impossible. I thought you meant that your MySQL database has ON DELETE CASCADE configured - is the first "DELETE FROM orange" above representing the ON DELETE CASCADE activity ? Assuming so, you would need to ensure that the apple->orange->banana relations are configured such that they work correctly in conjunction with ON DELETE CASCADE. This basically means to set "passive_deletes=True" so that no SELECT is issued to load in rows that may require deletion. Both relations also need to have cascade="all, delete-orphan" set up so that SQLAs management of already loaded objects understands that these collections are deleted along with the parent. Additionally, if apple CASCADEs to oranges, there is no need to issue an explicit session.delete() on each orange object - that can also produce conflicting activity. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
