InvalidRequestError from CrudRestController post()/put() or Sprox create()/update()

19 views
Skip to first unread message

Moritz Schlarb

unread,
Nov 12, 2012, 12:31:38 PM11/12/12
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
traceback.log
Message has been deleted

Moritz Schlarb

unread,
Nov 12, 2012, 1:05:55 PM11/12/12
to TurboGears, Sprox
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! ;)
Reply all
Reply to author
Forward
0 new messages