rails icon indicating copy to clipboard operation
rails copied to clipboard

Detect colliding keys in Active Job Hash serialization

Open sambostock opened this issue 1 year ago • 0 comments

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

sambostock avatar Jul 28 '22 07:07 sambostock