Mike, thanks so much for responding.
--- On Sat, 3/28/09, Michael Bayer <[email protected]> wrote: > From: Michael Bayer <[email protected]> > Subject: [sqlalchemy] Re: Getting "FlushError" trying to merge related > objects > To: [email protected] > Date: Saturday, March 28, 2009, 5:02 PM > Yassen Damyanov wrote: > > > > def _storeProfileToCache(self, profile): > > # this creates the object in memory, out of a > dictionary: > > newRecord = > CbRecord.createFromJsonDict(self.site, profile) > > > > # this gets a SA session: > > sess = OrmManager().newSession() > > > > cbRecord = sess.merge(newRecord) > > cbRecord.modified = None # a timestamp field > that must be updated > > sess.commit() > > sess.close() > > > > The sess.merge() call raises that error. The test that > fails tries to > > merge a CbRecord with five persons, two of which are > identical to those in > > the database (same primary key). I would expect the > result to be the > > database having the five persons stored and related to > the same CbRecord. > > I cant see here where the CbPerson record is created or how > it is > associated or not with the parent CbRecord. The error > means you have a > CbPerson in your session that was just created as a pending > (non-inserted) > record, and is not attached to a CbRecord. The strange thing is (I'm checking this in the debugger) -- the newRecord (which is CbRecord) looks perfect after creation -- all five persons are attached to it via the 'persons' collection; all 'parent' attributes are properly linked to the parent; the foreign key has proper value as well. After creation, the session is empty, so CbPerson objects not connected to a parent must have appeared somehow during the merge() call... Tracing the SA code shows that at time of raising the Error ('session.py, line 1400'; this is SA 0.5.3), the session does have three new CbPerson objects not connected to parents, who's attributes correspond to the new objects not yet existing in the database. It has also two dirty CbPerson who's attributes correspond to those already stored in the database. (I don't see the CbRecord object amongst the dirty objects at that time.) > If you require CbPerson objects to be inserted without this attachment, > don't use "delete-orphan" cascade. The "delete-orphan" is a must, as the foreign key is part of the primary key and cannot be nullified ... Can it be that the problem lies there? (My initial suspicion was that I do not understand the concept of merging, but Mike did not correct me at that ... so I am really stuck; any further ideas on how to fix this would be highly appreciated.) Thanks in advance, Yassen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
