IntegrityError is a subclass of Database - you need to catch psycopg2.database.integrityerror
On Tuesday, December 11, 2012 9:43:04 AM UTC-7, Richard wrote: > > Hello, > > I try to write a ondelete function that will try to delete a record and if > fall on the exception : <class 'psycopg2.IntegrityError'> > > Will trigger a flash message, here the code : > > def ondelete_func(form): > """try delete ondelete if database raise an error trigger a message > telling the user that the record can't be deleted""" > try: > crud.delete(db[request.args(0)], request.args(1)) > except IntegrityError: > session.flash = T('The record you try to delete is still > referenced by other records and can\'t be deleted') > > def create_update(): > """create update funciton""" > #crud.settings.update_ondelete = StorageList() > form = crud.update(db[request.args(0)], request.args(1), > ondelete=ondelete_func) > return dict(form=form) > > I also try with : "except psycopg2.IntegrityError:" > > No chance. > > Thanks > > Richard > --