Hi again, I have a problem with a cascade relation. Any help or clues would be greatly appreciated.
I have a model which has this relation: member = relation(Member,lazy=False,backref=backref ('members',order_by=memberID),cascade="all, delete, delete-orphan") When this cascade is active, it cause this insert to fail: def PUT(self,memberid,fields=None): memberProfile = MemberProfile(memberID=memberid) self.session.add(memberProfile) if fields: for field,value in fields.iteritems(): try: setattr(memberProfile,field,value) except: self.session.rollback() raise self.session.commit() with this error: Traceback (most recent call last): File "MemberInfo.py", line 93, in ? x.PUT(999999,{'firstname':'Gloria','lastname': 'W', 'password': '123456789', 'city':'anywhere', 'phonehome': 'xxxxxxxxxx','question': 'what?','answer':'.','lockoutflag':False,'deleteflag':False, 'activeflag':True, 'insuranceflag':False,'applicationstatusID':1}) File "MemberInfo.py", line 67, in PUT self.session.commit() File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 670, in commit self.transaction.commit() File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 375, in commit self._prepare_impl() File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 359, in _prepare_impl self.session.flush() File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 1354, in flush self._flush(objects) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 1407, in _flush raise exc.FlushError( sqlalchemy.orm.exc.FlushError: Instance <MemberProfile at 0x-489b1a34> is an unsaved, pending instance and is an orphan (is not attached to any parent 'MemberProfile' instance via that classes' 'member' attribute) When I change the relation back to this: member = relation(Member,lazy=False,backref=backref ('members',order_by=memberID)) My insert works, but my delete, appearing below: def DELETE(self,memberid,fields=None): memberProfile = MemberProfile(memberID=memberid) self.session.delete(memberProfile) Fails with this error: Traceback (most recent call last): File "MemberInfo.py", line 95, in ? x.DELETE(999999) File "MemberInfo.py", line 71, in DELETE self.session.delete(memberProfile) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.0rc4-py2.4.egg/ sqlalchemy/orm/session.py", line 1135, in delete raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: Instance '<MemberProfile at 0x-48976194>' is not persisted --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---