Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow disabling transactional callbacks on a model#56376

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kirs wants to merge1 commit intorails:main
base:main
Choose a base branch
Loading
fromkirs:disable-transactional-callbacks

Conversation

@kirs
Copy link
Member

All validations and model callbacks are wrapped intoBEGIN /COMMIT for transactional consistency.

However, in a large-scale apps with high concurrency and high DB connections usage, that brings the downside of thatBEGIN holding the connection from being reused by another workers.

On top of that, in a large scale app, you'd run in isolation level likeREAD COMMITTED where keeping callbacks part of the same txn doesn't give you much.

I've tried to write a version of this PR that would automatically kick in if the model has no callbacks, but then I've realized that validations are also part of this. And there's no good way to check whether validations are pure Ruby (validates :author_id, presence: true) or actual database (validates :author, presence: true).

So I've opted to make this a manual thing per model.

This would already help us at Shopify to save some connections usage across some very hot paths.

self.transactional_callbacks=false
end

deftest_save_without_callbacks_does_not_materialize_transaction

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's worth adding at least one test case that asserts the transactionis opened on the connection whentransactional_callbacks istrue.

There's no test case in this file that explicitly checks for that. The closest, I think, is"test_cancellation_from_before_filters_rollbacks_in_#{filter}" (line 715) that asserts the transaction gets rolled back when the validation fails, which technically does cover this behaviour but in a very oblique way.

Copy link
Member

@eileencodeseileencodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add a changelog? I also left a comment about the API.

:before_commit,
scope:[:kind,:name]

class_attribute:transactional_callbacks,instance_writer:false,default:true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does this make sense as an application wide setting as well? Something likeconfig.active_record.disable_transactional_callbacks = true?

I also think the controller level API should bedisable_transactional_callbacks and default tofalse. So it's clearer what's happening in a controller

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eileencodeseileencodeseileencodes requested changes

+1 more reviewer

@juniper-shopifyjuniper-shopifyjuniper-shopify left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@kirs@eileencodes@juniper-shopify

[8]ページ先頭

©2009-2025 Movatter.jp