forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on rails#52017 One concern raised by Xavier is users holding on the return value of `.current_transaction` beyond the point where it is committed / rolled back / invalidated. I believe this is an invalid use of the API, just like holding `ActiveRecord::Base.connection` beyond the scope of a request is. However we can be more explicit about it, so I changed the callback registration methods to raise an error when called on a finalized transaction. Another concern was the usability of the null-object in the Active Record notification payloads, and I agree that while the null-object make sense when calling `Model.current_transaction`, it doesn't make sense to include it in the payload of events. The goal of the `.current_transaction` API is to allow implementing transaction aware code in a streamlined way. The goal of the `:transaction` in events however it to allow logging whether a query was inside a transaction or not, so it's much more ergonomic for it to be nilable. So I kept Matthew's change that passes `transaction: nil` in `sql.active_record` events when not inside a transaction. I also added test coverage to make sure it behaves consistently whether we're inside a transactional test or not. I also kept the separation between internal and "user" transaction objects, as I think it's a nice way to limit the effectively exposed API, and prevent users from abusing that API too much. Co-Authored-By: Jean Boussier <[email protected]>
- Loading branch information
Showing
8 changed files
with
186 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.