Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactions don't return the result of the yielded block #145

Closed
matthewmcgarvey opened this issue Jan 30, 2021 · 3 comments · Fixed by #159
Closed

Transactions don't return the result of the yielded block #145

matthewmcgarvey opened this issue Jan 30, 2021 · 3 comments · Fixed by #159

Comments

@matthewmcgarvey
Copy link

It currently returns a boolean of whether or not the transaction was committed successfully

tx.commit unless tx.closed?

This is different than Rails, for instance, that does return that value https://github.com/rails/rails/blob/d5386cfba2ec5c80f09e37d44b87bcae9c6ab6a8/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L310-L312

I would rather get the result of the block rather than the vague boolean, though I know this will be a breaking change.

@bcardiff
Copy link
Member

I agree. I didn't consider the return value for this method.

@BrucePerens
Copy link

BrucePerens commented Jan 20, 2022

This has sat around for a while now. I think I would like to add #transaction! which:

  • Returns the value of the block unconditionally.
  • Raises a unique exception when the transaction is rolled back.

@bcardiff
Copy link
Member

The return value can be added to the existing method. There is no documentation for the return value. The current (nilable) boolean is accidental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants