Kevin Dangoor <[EMAIL PROTECTED]> writes:
> I'm thinking that expose will catch the exception, do a rollback and
> then raise it again. (If any exceptions occur during the commit, those
> will be raised). So, you can still define a _cpOnError method to
> display a proper message to the user.
I dunno if one common place is enough.
I might be doing something wrong or unusul, so let me describe and see if
somebody has some way to do it better ;-)
Lets imagine three database operations that uses forms:
- INSERT
- UPDATE
- DELETE
When doing an insert, you can be successful or not. The same for update and
delete. On success during insert I do tg_flash('record inserted at
database'), on sucess during update I do tg_flash('record updated') and on
success on delete I do tg_flash('record deleted'). On failure I set tg_flash
to the exception message. All of these are followed by a raise
cherrypy.HTTPRedirect(turbogears.url("/some_url/")) *BUT* on insert
"/some_url/" gets the "id" as an aditional parameter and automatically returns
in "editing mode", so the destination is "/some_url/id", hence a different
destination.
If I can trap the exception and abort everything by myself, that's OK and
nothing will change -- except that I'll remove "hub.begin()" from my methods
--, or if I can add more information and reraise the exception, so that I can
add the destination URL, nothing changes to me...
But I think that we're loosing a lot of flexibility just to save 2 or 3 lines
of code...
My application is simple, but I am thinking about something where you try
doing the operation and on failure you try a different thing (e.g. try
retrieving information and if it doesn't exist, add; try adding information,
if it exists then update, etc.).
> Currently, the code doesn't really give you a chance to nest
> transactions. I do realize there are some cases where you might want
> to do that... it's worth opening a ticket on. As of right this moment,
> though. the connection hub doesn't nest transactions.
One can always use sqlbuilder or run direct SQL commands to nest them
today... I agree that you loose portability, but if it is too important...
--
Jorge Godoy <[EMAIL PROTECTED]>