I was trying to hook in the wrong place!
Of course I need to do the rollback before the error_handler function is
called, which means before_call of new and edit!

It seems to work as done in
https://github.com/moschlar/SAUCE/commit/a7a2867cac8a255cbc6e804e33f922be3736b589

Still up for the discussion if it's a bug or a feature! ;)

Am 12.11.2012 18:31, schrieb Moritz Schlarb:
> Hi there you all.
> 
> I seem to have a problem regarding tgext.crud and Sprox when creating or
> updating objects:
> 
> If, due to, e.g. an unique Index over multiple columns or other advanced
> stuff, the flush in the Sprox SAORMProvider create() and update()
> methods throws an IntegrityError, the catch_errors decorator on
> CrudRestController catches that exception and flashes its message.
> 
> So far, so good, BUT, and this is were I'm not sure if it's a bug or if
> I'm just doing something very stupid without knowing: I get an
> InvalidRequestError (see traceback attached) while rendering the
> previous form page again.
> Apparently, this is because I use objects (e.g. an instance of Event in
> that case) from the session to dynamically generate a menu on the page.
> These objects aren't accessible due to the transactions failed state.
> If I follow the instructions from the traceback Exception and wrap the
> code for provider.create with try..except and issue a
> provider.session.rollback(), I can get it to work.
> 
> Sadly, I can't hook the post and put methods because before_render never
> gets called due to the exception...
> 
> Now the final question is:
> - Am I doing anything stupid with my session-bound objects?
> - Should CrudRestController or even Sprox directly perform the rollback
> when the session.flush() fails?
> 
> Hoping for some insight ;)
> 
> Best wishes,
> 
> Moritz
> 

-- 
Moritz Schlarb

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to