-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Modifying params in the endpoint will change the default #1438
Comments
I think we probably don't want to clone the default every time, which could be unnecessarily expensive for every request, but definitely freeze it. |
@dblock If we freeze default, that might cause existing client code to suddenly start throwing RuntimeErrors (if they are mutating param values). Admittedly, they're probably not getting the behavior they expect on subsequent calls after the default has been modified. So there's already an error present. But it seems to me that the best course is to clone the default when it is assigned to a param. This is also appealing because it means that params are uniformly modifiable whether they have a default value or not. Freezing the default would cause the two cases to behave differently, which I think is a much more confusing semantic. Also, I haven't actually verified it, but I think the test spec above will only pass if default is cloned. If we freeze default, the slice! call is going to raise a RuntimeError. |
I worry about unintentional performance overheads, but maybe I am worried about nothing. Either way I'll take a PR. |
This was fixed in 8b72144. |
awesome! Thanks! 👍 |
When using
default
of a param, modifying the param within the request will change the default. Here is a spec for the issue:For the first
get
in the spec, default is correct which is-created_at
but on the second get, default sort param has changed tocreated_at
because ofparams[:sort].slice!(0)
inget
.Ideally we'd need to pass a
clone
of params, as an alternative we may need tofreeze
default.The text was updated successfully, but these errors were encountered: