Moritz Schlarb
unread,Nov 12, 2012, 12:31:38 PM11/12/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to TurboGears, Sprox
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