On Nov 16, 7:51 pm, John Firebaugh <[email protected]> wrote:
> Shouldn't the transaction around Model#_save be rolled back if one of
> the before hooks returns false?
>
> It will be if raise_on_save_failure is set to true because that raises
> an exception, but if raise_on_save_failure is false, the transaction
> is committed even though the save fails.

What's the use case for this?  The before hooks are the first things
run, so the only thing I can think of is you want to rollback changes
made by a previous before hook.  Is that why you want this?

You could probably implement this by raising Rollback in save_failure
if raise_on_save_failure is false, and modifying Model#save to rescue
Rollback if transactions aren't being used.  I'm not sure I like that
approach, though, unless you are checking whether or not transactions
are being used, as otherwise you could be swallowing exceptions that
you didn't generate (such as the user raising Rollback in a before
hook).

I guess there are three possibilities that need to be considered:

1) raise_on_save_failure true: No modifications needed, as it raises
an exception that rolls back the transaction and is reraised.
2) raise_on_save_failure false and use_transaction true: can raise
Rollback, which the transaction code will take care of.
3) raise_on_save_failure false and use_transaction false: should just
return false, as raising Rollback and catching it makes it impossible
to differentiate between the a before hook returning false and a user
raising Rollback in a before hook (which they expect to bubble up to
their own transaction code).

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to