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

Fix NoMethodError when ActionController::Metal#response is an Array #420

Merged
merged 2 commits into from
May 31, 2018

Conversation

delner
Copy link
Contributor

@delner delner commented May 9, 2018

When ActionController::Metal#response was an Array instead of a ActionDispatch::Response, tracing raised an error. This manifested in Devise's FailureApp which is overriding the value of response with an Array, in an unexpected way. You can reproduce this by attempting to login with bad credentials.

Only affects users who use Devise and ddtrace 0.12.0.

This pull request attempts to handle both ActionDispatch::Response and Array responses, and if it doesn't receive either, it doesn't set a status.

Addresses #419

@delner delner added bug Involves a bug integrations Involves tracing integrations labels May 9, 2018
@delner delner self-assigned this May 9, 2018
@delner delner requested a review from palazzem May 9, 2018 22:05
@delner delner changed the title Fixed: NoMethodError when ActionController::Metal#response is an Array. Fix NoMethodError when ActionController::Metal#response is an Array May 9, 2018
when ActionDispatch::Response
response.status
when Array
status = response.first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first element always contain the status? If yes, can you add a comment explaining why the first and if we have to change this behavior in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's always the first because that's the Rack response standard: status code, headers, body.

palazzem
palazzem previously approved these changes May 10, 2018
@delner
Copy link
Contributor Author

delner commented May 10, 2018

Pull request for Devise opened here: heartcombo/devise#4871

Copy link
Contributor

@pawelchcki pawelchcki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small question about disabling rubocop warning. Otherwise looks Good!

@@ -231,6 +232,20 @@ def process_action(*args)
ensure
Datadog::Contrib::Rails::ActionController.finish_processing(payload)
end

# rubocop:disable Style/EmptyElse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the benefits of using empty else here ?

Also is # rubocop:disable Style/EmptyElse reenabled after the scope of this method ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I thought that a case block would return the object passed into the case statement if none of the branches are hit. Since I wanted it to return nil, I thought I needed to be explicit. Turns out its just another one of those weird language things where it does in fact return nil if no branches are met. Probably should remove it then.

@delner delner force-pushed the bugfix/devise_failure_app_mishandled_response branch from f579dfb to f9a9635 Compare May 23, 2018 19:05
@delner
Copy link
Contributor Author

delner commented May 23, 2018

@pawelchcki Feedback addressed.

@pawelchcki
Copy link
Contributor

Thanks @delner, looks good.

@delner delner merged commit 370e9e9 into master May 31, 2018
@delner delner deleted the bugfix/devise_failure_app_mishandled_response branch May 31, 2018 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants