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
ActionDispatch::Routing::RouteSet::Generator mutates request.path_parameters #24392
Comments
Can you create an executable test script using one of the templates here, that would demonstrate the problem you are seeing? |
I've tried writing a test case, and failed. And will absolutely try again :-) But just looking at the |
Executable test script here: https://gist.github.com/bquorning/83a7689c50500500fd94773c14808b74 I’ve marked the 1 line you can remove to make the test pass. |
Bug script fails for me on master. Would you be willing to work on a pull request for this? |
The
For the
I’ll try going with 2). |
@bquorning this a duplicate of #23019 - I've tried doing a fix in #23103 but found some regressions in the changes that aren't tested in the current test suite. Will take another look at it this week. |
I think a fix might be as easy as calling def normalize_action!
if @options[:action] == 'index'.freeze
@recall[:action] = @options.delete(:action)
end
end Test coverage is pretty sparse, though, so I'm not sure if this introduces new regressions. |
@bquorning yeah, I sure we could just |
Yeah, I agree. My observation is just that |
Thanks for the report. I was OOO last week. I'll try to take a look soon. That hash dup was pretty expensive :( |
@schneems Are you sure the recall dup was expensive? I just tested the example script above with memory_profile, both with and without dup, and the difference was 300 bytes. Is there a test case where this recall hash is significantly bigger? |
I think the concern is that the |
I did some investigation on the code base, and here are my results. Please let me know if this makes sense:
|
Fix in #23103 |
I’m having some trouble upgrading to Rails 5.0.0.beta3, and it looks like #21057 is to blame.
In a controller, I can trigger an
ActionController::UrlGenerationError
exception by calling e.g.root_path
right before callingurl_for
. In ashow
action, I would get something like this message:No route matches {:action=>"index", :controller=>"foo", :id=>"42"}
. Notice howurl_for
thinks the currentshow
action is anindex
action… This is becauseActionDispatch::Routing::RouteSet::Generator
is mutatingrequest.path_parameters
.The commits 1993e2c and 1a14074 remove the
dup
of therecall
andoptions
hashes, and changes a subsequent call to@recall.delete
.But there are still several ways to mutate the original objects. I’m seeing these calls:
My problems are fixed by changing only
@recall = recall
into@recall = recall.dup
, but I would rather we fixed the mutation problems instead.r? @schneems
The text was updated successfully, but these errors were encountered: