On Saturday, July 27, 2019 at 4:53:06 PM UTC-4, Nestor Diaz wrote: > > it then raise an exception, however I can not > catch the exception, even if I set up a try-catch block, however if I > add a DBSession.flush() inside the try, the sql sentence is executed and > therefore I can catch the exception. > ...
The question is: Do I have to 'flush()' everytime to be sure the sql > sentence is executed, or there is a better way, or which way do you > suggest to manage the exceptions ? This is because in your specific application, you are using the `pyramid_tm` package. `pyramid_tm` simplifies transaction based application development by wrapping your pyramid views in a 'tween' , where 'BEGIN' is issued before your view executes and a ROLLBACK or COMMIT is issued after your view executes. The integrity error is raised by the database, so it is only raised by your explicit 'flush' or the implicit flush which pyramid_tm invokes during the 'commit' in it's tween /after/ your view executes. The pyramid_tm docs have a section with dealing with errors, which goes into the 'custom error page' pattern that Mike brought up, along with some other patterns that involve making your error information persist. https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/ -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/242592cd-3c20-4fdd-be8f-ff12d549f708%40googlegroups.com.