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

Do not convert Rack::Response to Rack::Response #1045

Merged
merged 1 commit into from
Jun 25, 2015

Conversation

dmitry
Copy link
Contributor

@dmitry dmitry commented Jun 25, 2015

While using https://github.com/aserafin/grape_logging grape middleware after an upgrading grape from 0.11 to 0.12 I've been stuck with an issue (aserafin/grape_logging#6):

NoMethodError (undefined method `downcase' for 2:Fixnum)

That's because Middleware#response tries to convert Rack::Response to Rack::Response and fails.

@dblock
Copy link
Member

dblock commented Jun 25, 2015

Ouch. Can you please add a line to the CHANGELOG? I will probably cut a dot release with this since it's a regression.

While using https://github.com/aserafin/grape_logging grape middleware after an upgrading grape from 0.11 to 0.12 I've been stuck with an issue:

```
NoMethodError (undefined method `downcase' for 2:Fixnum)
```

That's because `Middleware#response` tries to convert `Rack::Response` to `Rack::Response` and fails.
@dmitry dmitry force-pushed the fix/do-not-convert-rack-response branch from 4e0fc3a to 7ad647a Compare June 25, 2015 14:28
@dmitry
Copy link
Contributor Author

dmitry commented Jun 25, 2015

@dblock Rebased with CHANGELOG file.

dblock added a commit that referenced this pull request Jun 25, 2015
Do not convert Rack::Response to Rack::Response
@dblock dblock merged commit b8b6053 into ruby-grape:master Jun 25, 2015
@dblock
Copy link
Member

dblock commented Jun 25, 2015

Merged.

@kushkella
Copy link

Just ran into this problem. Will really appreciate a new release! Thanks!

@AndyDangerous
Copy link

I was just having the same problem, and I wonder if this PR fully fixes it. After building the gem from the latest source, I still had the problem, but it goes away when using 0.11.0.

@johnsinco
Copy link

+1. Still seeing this exact error message after building a 0.12.1 version from master.

@dmitry
Copy link
Contributor Author

dmitry commented Jul 7, 2015

What about using gem 'grape', github: 'intridea/grape'?

@AndyDangerous
Copy link

@dmitry That ought to be the same code in master, right? In any case, the problem is still there.

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

@AndyDangerous can you show the full stacktrace?

@dmitry dmitry deleted the fix/do-not-convert-rack-response branch July 8, 2015 11:24
@AndyDangerous
Copy link

Here it is, @dmitry

2015-07-08 14:42:34 +0000: Rack app error: #<NoMethodError: undefined method `downcase' for 2:Fixnum>
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/utils.rb:501:in `[]'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/response.rb:53:in `[]'                                                                                                                                                                                                              4 /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `call'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/middleware/error.rb:27:in `block in call!'                                                                                                                                                                         6 /usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/middleware/error.rb:26:in `catch'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/middleware/error.rb:26:in `call!'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/middleware/base.rb:18:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/endpoint.rb:196:in `call!'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/endpoint.rb:184:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/api.rb:114:in `call'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/api.rb:44:in `call!'
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/grape-735034b2486e/lib/grape/api.rb:39:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'                                                                                                                                                     22 /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/config.rb:17:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/rack_patch.rb:13:in `call'                                                                                                                                                                                                        24 /usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/configuration.rb:51:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/server.rb:507:in `handle_request'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/server.rb:375:in `process_client'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/server.rb:262:in `block in run'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/thread_pool.rb:104:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/puma-2.11.3/lib/puma/thread_pool.rb:104:in `block in spawn_thread'

@patfrat
Copy link

patfrat commented Jul 8, 2015

Got the same error today on one of my project using Grape 0.12.0 !

Unexpected error while processing request: undefined method `downcase' for 2:Fixnum
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/utils.rb:501:in `[]'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/response.rb:53:in `[]'
    /var/lib/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:650:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:27:in `block in call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:26:in `catch'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:26:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/base.rb:18:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/endpoint.rb:196:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/endpoint.rb:184:in `call'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:98:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:33:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:29:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:33:in `block in call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:24:in `each'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:24:in `call'
    /var/lib/gems/2.1.0/gems/rack-contrib-1.3.0/lib/rack/contrib/post_body_content_type_parser.rb:36:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
    /var/lib/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/deflater.rb:35:in `call'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
    /var/lib/gems/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:1054:in `call'
    /var/lib/gems/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:1054:in `block in spawn_threadpool'

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

@patfrat you have to use grape from master, because this patch isn't released in a new gem yet.

@patfrat
Copy link

patfrat commented Jul 8, 2015

Grape 0.10.0 is working for me ... not 0.11.0 nor 0.12.0

@patfrat
Copy link

patfrat commented Jul 8, 2015

@dmitry i use grape from master in my project
I have tested also grape v0.12.1 and it's still on error

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

Is it happens while tests or in a development/production mode?

@AndyDangerous
Copy link

For us, it was in development.

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

@AndyDangerous @patfrat I believe you have to move grape middleware upper than ConnectionManagement to resolve this issue. But for sure it's not related to this issue at all.

Basically you are experiencing an issue inside ConnectionManagement because it wants an array of response, but receives instance of a class Rack::Response instead.

@patfrat
Copy link

patfrat commented Jul 8, 2015

In development mode too
I have tested with downgrading active-support in version 4.2.1 and using grape 0.12.0
Still the same error !

Unexpected error while processing request: undefined method `downcase' for 2:Fixnum
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/utils.rb:501:in `[]'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/response.rb:53:in `[]'
    /var/lib/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:650:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:27:in `block in call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:26:in `catch'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/error.rb:26:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/middleware/base.rb:18:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/endpoint.rb:196:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/endpoint.rb:184:in `call'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
    /var/lib/gems/2.1.0/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:98:in `call'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:33:in `call!'
    /var/lib/gems/2.1.0/gems/grape-0.12.0/lib/grape/api.rb:29:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:33:in `block in call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:24:in `each'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/cascade.rb:24:in `call'
    /var/lib/gems/2.1.0/gems/rack-contrib-1.3.0/lib/rack/contrib/post_body_content_type_parser.rb:36:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
    /var/lib/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:in `call'
    /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/deflater.rb:35:in `call'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
    /var/lib/gems/2.1.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
    /var/lib/gems/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:1054:in `call'
    /var/lib/gems/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:1054:in `block in spawn_threadpool'

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

How do you mounting grape API?

@patfrat
Copy link

patfrat commented Jul 8, 2015

I am using Rack::Cascade.new [Api, ApiDoc, statics]
My API use grape-activerecord v 0.0.8 and activerecord and activesupport 4.2.1

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

@patfrat but where do you put this Rack::Cascade instance?

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

I believe we have to stop chatting here about your issues, and you have to create a new issue... because it's unrelated to this this fix at all.

@patfrat
Copy link

patfrat commented Jul 8, 2015

ok @dmitry

@dmitry
Copy link
Contributor Author

dmitry commented Jul 8, 2015

#1059

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.

6 participants