On Mar 30, 2009, at 3:35 AM, Yassen Damyanov wrote:
> > 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.) can you produce a small test case illustrating this ? we have tests exercising merge() in conjunction with delete-orphan cascade but perhaps there is a bug here. basically you're saying if a cbRecord with two cbPerson objects is merged, it fails. I just created a simple test which passes: def test_orphan(self): mapper(User, users, properties={ 'addresses':relation(Address, backref='user', cascade="all, delete-orphan") }) mapper(Address, addresses) u = User(name='fred', addresses=[Address(email_address='e1'), Address(email_address='e2')]) sess = create_session() u1 = sess.merge(u) sess.flush() BEGIN INSERT INTO users (name) VALUES (?) ['fred'] INSERT INTO addresses (user_id, email_address) VALUES (?, ?) [1, 'e1'] INSERT INTO addresses (user_id, email_address) VALUES (?, ?) [1, 'e2'] COMMIT --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---