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

Rails/TransactionExitStatement - Inspect #with_lock method too #710

Merged

Conversation

FunnyHector
Copy link
Contributor

@FunnyHector FunnyHector commented Jun 2, 2022

ActiveRecord::Locking::Pessimistic#with_lock implicitly opens a transaction, so we should inspect this method as well as ActiveRecord::Transactions#transaction.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@FunnyHector FunnyHector force-pushed the transaction_exit_statement-with_lock branch from d2722f5 to 07d4157 Compare June 2, 2022 02:46
@FunnyHector FunnyHector marked this pull request as draft June 2, 2022 02:47
@FunnyHector FunnyHector force-pushed the transaction_exit_statement-with_lock branch from 07d4157 to 74c608a Compare June 2, 2022 02:49
`ActiveRecord::Locking::Pessimistic#with_lock` implicitly opens a
transaction, so we should inspect this method as well as
`ActiveRecord::Transactions#transaction`.
@FunnyHector FunnyHector force-pushed the transaction_exit_statement-with_lock branch from 74c608a to 7502d86 Compare June 2, 2022 02:56
@FunnyHector FunnyHector marked this pull request as ready for review June 2, 2022 02:57
@koic koic merged commit 88d6656 into rubocop:master Jun 2, 2022
@koic
Copy link
Member

koic commented Jun 2, 2022

Thanks!

@FunnyHector FunnyHector deleted the transaction_exit_statement-with_lock branch June 2, 2022 05:12
@javierjulio
Copy link
Contributor

Having dug around the Rails discussions, I noticed this change rails/rails#39453 was committed which seems to make this cop condition not applicable. I'm using with_lock and doing an early return if a condition isn't meant just like the following rails/rails#29333 (comment) but with the followup I don't think a warning would be made. Are we sure this cop should be reporting for with_lock?

@FunnyHector
Copy link
Contributor Author

FunnyHector commented Jun 19, 2022

Having dug around the Rails discussions, I noticed this change rails/rails#39453 was committed which seems to make this cop condition not applicable. I'm using with_lock and doing an early return if a condition isn't meant just like the following rails/rails#29333 (comment) but with the followup I don't think a warning would be made. Are we sure this cop should be reporting for with_lock?

@javierjulio I see, I didn't dig into how this deprecation was implemented in Rails, and wasn't aware of "no warning if not written" (rails/rails#39453).

If I'm understanding rails/rails#39453 correctly, neither should with_lock or transaction be flagged by this cop, right? At least not without some updates to detect whether there is any data written.

@javierjulio
Copy link
Contributor

@FunnyHector yes, I think you're right. My main concern was just with with_lock since I have 2 instances in the same class that were reported by Rubocop after upgrading but neither instance performs a write if returned. My understanding is the same as yours, I think this cop wouldn't apply now unless we can detect that data is being written in either with_lock or transaction now.

@FunnyHector
Copy link
Contributor Author

@javierjulio I'll raise an issue for this. Thanks for this opportunity to learn more about Rails 👍

@javierjulio
Copy link
Contributor

@FunnyHector sounds good, thank you! ❤️

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

Successfully merging this pull request may close these issues.

None yet

3 participants