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

Detect colliding keys in Active Job Hash serialization #45676

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sambostock
Copy link
Contributor

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

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.

None yet

1 participant