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

Always pass a mutable keyword arguments hash to filters #88

Merged
merged 1 commit into from
Oct 14, 2020

Conversation

dylanahsmith
Copy link
Contributor

Problem

While looking at application test failures for #60, I noticed a few FrozenError: can't modify frozen Hash exceptions in one of the filters. The filter was modifying the options hash that was passed to it.

Actually, the rb_hash_freeze(const_keyword_args); line in that PR (https://github.com/Shopify/liquid-c/pull/60/files#r504912592) is missing on master, but it is passing the same hash to filter call. That could result in even more subtle problems. As mentioned on the common for that line

I think we are going to have to always freeze or always dup the hash. Otherwise, it is too easy to test a filter using dynamic keyword arguments and then get errors in production when a frozen hash is passed in for constant keyword arguments.

Solution

Most filters take positional arguments, so it might not be worth trying to optimize for constant keyword arguments at the moment. So I've just removed that special case to make the code simpler, by always building a new hash for filter keyword arguments.

@dylanahsmith dylanahsmith merged commit aa0b3bf into master Oct 14, 2020
@dylanahsmith dylanahsmith deleted the no-const-kw-hash branch October 14, 2020 19:49
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.

2 participants