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

Fix RedisCacheStore#write_multi with :expires_in #49974

Merged

Conversation

fatkodima
Copy link
Member

Fixes #49973.

This options were extracted as keyword arguments and not used then.

@fatkodima
Copy link
Member Author

Wdyt about enabling a relevant rubocop's cop for this in a follow up PR - https://docs.rubocop.org/rubocop/1.57/cops_lint.html#lintunusedmethodargument ? With it, this bug would be detected earlier.

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

key = SecureRandom.uuid
@cache.write_multi({ "#{key}" => 1 }, expires_in: 10)

Time.stub(:now, time + 11) do
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not use travel here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Copy paste from the above test.
Just noticed another problem - "#{key}" , interpolation is not needed. A work for another rubocop cop Style/RedundantInterpolation. I noticed a few offenses of it in rails. Do you think its worth enabling?

Copy link
Member

Choose a reason for hiding this comment

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

Personally, no. Although I can't remember specific examples, I know there have been times when I preferred to write "#{foo}" instead of foo.to_s for stylistic reasons.

Also, given Ruby's lack of static typing, it seems like such a cop might not be very reliable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, no problems. This cop just detects patterns like "#{foo}" and suggests to replace them with foo.to_s (as a safe option), but many times this can be just written as foo.

@jonathanhefner
Copy link
Member

Wdyt about enabling a relevant rubocop's cop for this in a follow up PR - https://docs.rubocop.org/rubocop/1.57/cops_lint.html#lintunusedmethodargument ? With it, this bug would be detected earlier.

I think it would depend on what the end result looks like for the entire Rails code base.

Personally, I am not a fan of prefixing arguments with _, whether they are unused or not. Also, there doesn't appear to be a way to enforce the reverse. i.e. If an argument goes from being unused to used, removal of the _ prefix is not enforced.

@fatkodima fatkodima force-pushed the fix-redis-write_multi-with-expires_in branch from ad0c89b to 096201f Compare November 8, 2023 21:28
@jonathanhefner jonathanhefner merged commit c36f877 into rails:main Nov 8, 2023
4 checks passed
@jonathanhefner
Copy link
Member

jonathanhefner commented Nov 8, 2023

Thank you, @fatkodima! ✍️

Backported to 7-1-stable in f6987c4.

jonathanhefner added a commit that referenced this pull request Nov 8, 2023
…xpires_in

Fix `RedisCacheStore#write_multi` with `:expires_in`

(cherry picked from commit c36f877)
@fatkodima fatkodima deleted the fix-redis-write_multi-with-expires_in branch November 8, 2023 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using redis_cache_store, Rails.cache.write_multi does not set TTL correctly
2 participants