On Jan 30, 2009, at 5:50 AM, Alessandro Dentella wrote:
> > Hi, > > i'm trying to understand how to cope with errors from the database > and I > don't completely understand the following behaviour. > > I try to delete a Project that has integrity constrains, so > correctly the > db complains and SA raises an OperationalError. Right now I'm not > trying > to understand how to *prevent* this. I just want to understand how > to give > a message to the user and restore a working situation. > > [I'm working with postgreSQL and SA 5.0rc4] > > > def delete_obj(obj): > print "### deleting obj", repr(obj) > try: > session.delete(obj) > print "session.delete:", session.deleted > session.commit() > except Exception, e: > print "Problemi...", e.message > session.rollback() > > q = session.query(Project) > prj = q.filter_by(id=18).one() > > print repr(prj) > delete_obj(prj) > > print "session.delete:", session.deleted > for obj in session: > print "obj", hex(id(obj)), type(obj) > > > print "Project", prj ### <<<<<<< this code raises the > Interface error > > > where is the problem? the connection (as I tend to believe) or the > object 'prj'? > > What's the state in which is now the object 'prj'? What should I > do to > go back to the previous situation? > > What exacltly means InterfaceError - connection already closed. I > simply > issued a .rollback(), why should it be closed? How should I test > if a > connection is closed? and how should I open it again? "connection already closed" is a psycopg2 error indicating that the socket has been shut down. looking at your output, I see a raw execute() occuring within the string conversion of your Project object and theres a module called sqlkit/db/utils.py causing an exception throw. SQLA's rollback then fails too but probably for the same reason. since you're executing directly off of the engine there, it would seem unrelated to the state of the connection related to the session. its not apparent why the socket would be shut down, however, unless the database were restarted perhaps. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---