Skip to content

Overwrite unreadable entries in write with unless_exist - #320

Open
afurm wants to merge 1 commit into
rails:mainfrom
afurm:fix-unless-exist-unreadable-entry
Open

afurm wants to merge 1 commit into
rails:mainfrom
afurm:fix-unless-exist-unreadable-entry

Conversation

@afurm

@afurm afurm commented Oct 11, 2026

Copy link
Copy Markdown

write(name, value, unless_exist: true) raises NoMethodError (undefined method expired? for nil) when the stored entry cannot be deserialized, for example an old raw value, a different serializer, or a corrupt row. read already treats these as a miss.

This treats a nil entry as missing, so the write goes through. I added a regression test.

`write(name, value, unless_exist: true)` deserializes the stored row to
check whether it has expired. `deserialize_entry` returns nil when the
payload can't be loaded (an old raw value, a payload from another coder,
or a corrupt row), so the check raised `NoMethodError: undefined method
'expired?' for nil`.

`read` already treats such a row as a miss, so treat it as missing here
too and write the new value.
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.

1 participant