rails
rails copied to clipboard
Detect colliding keys in Active Job Hash serialization
Summary
ActiveJob serializes Symbol
Hash
keys by stringifying them, and storing an array of keys to be symbolized on deserialization as _aj_symbol_keys
. This means that if a Hash
has both Symbol
and String
keys with the same contents, they will collide.
Specifically, the resulting hash ends up containing only a pair consisting of:
- the symbol key
- the last value
This PR adds a check for this and logs a deprecation warning. It also introduces a setting to raise
instead of logging the warning, with the intention of making this behavior the default in Rails 7.2/8.0.
Other Information
I have left a number of placeholders for the time being, because I wanted to get initial review and confirm we want to do this, before investing the time to write the docs, deprecation message, changelog, etc.
cc. @mangara, who mentioned this in Slack