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

Nested models error: " undefined method `reverse' for nil:NilClass " #27

Open
kapellan opened this issue Apr 16, 2013 · 11 comments
Open

Comments

@kapellan
Copy link

Hello! I use nested models(think reason near this) and hard relations between them. When I try to create some model instance, i get such error in create action.

NoMethodError in AdvertsController#create
undefined method `reverse' for nil:NilClass

When gem is disabled - error disappears.

@furiabhavesh
Copy link

We are also facing same issue which does not come if we remove this gem.

@rubenrails
Copy link

Same error here.

@sudhirj
Copy link

sudhirj commented Aug 19, 2013

That's a +1. The error happens here:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb#L14

Is QR setting binds to nil or something?

@jdelStrother
Copy link

I could be wrong, but I believe this is caused by Rails running its built-in EXPLAIN query, and QueryReviewer running an EXPLAIN on that. I'm not sure it's anything to do with nested models.

[EDIT: nevermind, I just reproduced it without an EXPLAIN. So much for that theory...]

@laurens
Copy link

laurens commented Sep 3, 2013

@laurens
Copy link

laurens commented Sep 3, 2013

It works for me when going back to query_reviewer 0.1.6

@laurens
Copy link

laurens commented Sep 3, 2013

No, unfortunately it does not. But this seems only to happen on POST requests.

@nesquena
Copy link
Owner

nesquena commented Sep 3, 2013

Hmm, anyone have a working theory for what's causing this? Unfortunately not using this project at the moment but still maintaining and happy to accept patches.

@jdelStrother
Copy link

Is everyone here using the mysql2 gem, and only seeing it on inserts?

@jdelStrother
Copy link

So... I can reproduce just by loading up Rails console, enabling query reviewer with :

Thread.current["queries"] = QueryReviewer::SqlQueryCollection.new; Thread.current["query_reviewer_enabled"] = true

and then performing an insert (eg Post.create()).

The problem seems to result from some state being stored in the mysqladapter itself:

ActiveRecord::ConnectionAdapters::DatabaseStatements#insert calls DatabaseStatements#to_sql(arel, binds). If you call arel.to_sql after this point, (like QueryReviewer does in sanitize_strings_and_numbers_from_sql), then you'll hit the undefined method 'reverse' for nil:NilClass error. If you call arel.to_sql before this point, it works fine.

I think the problem results from the BindSubstitution class, which once you've run DatabaseStatements#to_sql stashes an @block ivar which changes the behaviour of to_sql. My head is starting to hurt following all the arel visitor methods though, so I'm struggling to pin it down much further.

@eyaleizenberg
Copy link

This error is still happening on rails 3.2.13 with latest query reviewer.

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

No branches or pull requests

8 participants