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

Migrating problems with pg_search to Heroku #90

Closed
ayl opened this issue Feb 26, 2013 · 11 comments
Closed

Migrating problems with pg_search to Heroku #90

ayl opened this issue Feb 26, 2013 · 11 comments

Comments

@ayl
Copy link

ayl commented Feb 26, 2013

Hey everyone,

I'm having problems with migrating an existing Rails 2.3.17 app to Heroku. It works totally fine with my custom EC2 Rails stack but on Heroku Cedar with Postgres 9.1 I can't seem to get it to work.

In my Gemfile I have:

gem "pg","~> 0.14.1"
gem "pg_search", "~> 0.2.1"

In my model I have:

class User < ActiveRecord::Base
    include PgSearch
    pg_search_scope :search_by_full_name, :against => [:first_name, :last_name, :login] 

When I run it in the console:

ayl$ heroku run console production
Running `console production` attached to terminal... up, run.6486
Loading production environment (Rails 2.3.17)
> User.search_by_full_name("asdf")
NoMethodError: undefined method `search_by_full_name' for #<Class:0x00000004cd41b0>
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-2.3.17/lib/active_record/base.rb:2002:in `method_missing'
    from (irb):1
    from /usr/local/bin/irb:12:in `<main>'

I've been beating my head against the wall trying to figure this out to no avail... Help?

@nertzy
Copy link
Collaborator

nertzy commented Feb 28, 2013

It's very strange that it says the method isn't defined. It's also strange that it doesn't give a better name for your User class. #<Class:0x00000004cd41b0> is very odd. Is there something strange going on with loading your models? Is your User class only defined in app/models/user.rb and nowhere else in your load path?

@ayl
Copy link
Author

ayl commented Feb 28, 2013

I agree that the message that I got for the class name instead of "User" is very odd. One of the main things I had to do when I was migrating from EC2 to Heroku was transitioning to Bundler. I doubt that could have caused the problem but I can't really think of anything else. The User model is only defined in app/models/user.rb

@ayl
Copy link
Author

ayl commented Feb 28, 2013

Sorry to keep adding to my own thread here, but I also realized that I while I was migrating I upgraded from rails 2.3.16 on EC2 to 2.3.17 on Heroku. So I was wondering if something changed in rails 2.3.17 and I found this on StackOverflow:

http://stackoverflow.com/questions/14928813/injecting-a-scope-through-an-association-extension-in-rails-2-3-17

I wonder if there's something different about the way scope methods could be added to classes in rails 2.3.17

@nertzy
Copy link
Collaborator

nertzy commented Feb 28, 2013

No problem. I appreciate all the information you can give me!

Yeah, I haven't been actively maintaining 0.2.x support against Rails 2.3, so I don't know anything about what has happened with recent 2.3 releases.

Does it only break on Heroku? If you call the same code in a local development environment, what happens?

I don't have enough time to look into this issue, but if you are able to figure out a solution, I will gladly accept a pull request and release a new 0.2.x version of pg_search. Sorry I can't help more!

@nertzy nertzy closed this as completed Feb 28, 2013
@ayl
Copy link
Author

ayl commented Mar 2, 2013

So I actually downgraded my rails installation on Heroku to match EC2 and it still works on my EC2 stack and not on Heroku.

Then I took the time to replicate my rails 2.3.16 stack with Engineyard local with the exact same environment to the best of my ability and it still did not work. I think there must be something wrong? I even got rid of Bundler and copied the exact same code.

I'm at my wits end now.

@nertzy
Copy link
Collaborator

nertzy commented Mar 3, 2013

I would try downgrading Rails to the version that was working before on AWS just to make sure that the Rails upgrade was the core cause. It sounds like it has nothing to do with Heroku.

I hope you can figure out an answer. My best advice is to upgrade to Rails 3 because Rails 2.3 has not been supported with security updates for some time.

openfirmware added a commit to openfirmware/pg_search that referenced this issue Jul 5, 2013
@openfirmware
Copy link

I am running a legacy Rails app on 2.3.18 with Bundler and Ruby 1.9.3, and ran into the same issue as @ayl:

>> Profile.search
NoMethodError: undefined method `search' for #<Class:0x007fa74dacfed0>
        from /Users/jpbadger/.rvm/gems/ruby-1.9.3-p429@geocens23/gems/activerecord-2.3.18/lib/active_record/base.rb:2002:in `method_missing'
        from /Users/jpbadger/.rvm/gems/ruby-1.9.3-p429@geocens23/gems/will_paginate-2.3.16/lib/will_paginate/finder.rb:170:in `method_missing
_with_paginate'
        from (irb):1

This seemed odd, as Profile.pg_search_scope was defined. I hadn't upgraded anything else recently, only trying to replace Sunspot with pg_search. I tried running the code in the diff on my Profile class:

>> Profile.respond_to?(:scope)
=> true
>> Profile.protected_methods.include?('scope')
=> false
>> Profile.scope
NoMethodError: protected method `scope' called for #<Class:0x007f9935f920d8>
        from /Users/jpbadger/.rvm/gems/ruby-1.9.3-p429@geocens23/gems/activerecord-2.3.18/lib/active_record/base.rb:2002:in `method_missing'
        from /Users/jpbadger/.rvm/gems/ruby-1.9.3-p429@geocens23/gems/will_paginate-2.3.16/lib/will_paginate/finder.rb:170:in `method_missing
_with_paginate'
        from (irb):3
        from /Users/jpbadger/.rvm/rubies/ruby-1.9.3-p429/bin/irb:16:in `<main>'
>> Profile.named_scope
ArgumentError: wrong number of arguments (0 for 1)
        from /Users/jpbadger/.rvm/gems/ruby-1.9.3-p429@geocens23/gems/activerecord-2.3.18/lib/active_record/named_scope.rb:86:in `named_scope
'
        from (irb):4
        from /Users/jpbadger/.rvm/rubies/ruby-1.9.3-p429/bin/irb:16:in `<main>'
>> Profile.protected_methods
=> [:with_scope, :with_exclusive_scope, :subclasses, :default_scope, :scoped?, :scope, :scoped_methods, :current_scoped_methods, :compute_typ
e, :class_of_active_record_descendant, :class_name_of_active_record_descendant, :sanitize_sql_for_conditions, :sanitize_sql, :sanitize_sql_fo
r_assignment, :aggregate_mapping, :expand_hash_conditions_for_aggregates, :sanitize_sql_hash_for_conditions, :sanitize_sql_hash, :sanitize_sq
l_hash_for_assignment, :sanitize_sql_array, :sanitize_conditions, :replace_bind_variables, :replace_named_bind_variables, :expand_range_bind_
variables, :quote_bound_value, :raise_if_bind_arity_mismatch, :validate_find_options, :set_readonly_option!, :encode_quoted_value, :method_mi
ssing_with_paginate, :wp_count, :wp_parse_options, :construct_calculation_sql, :execute_simple_calculation, :execute_grouped_calculation, :pr
eload_associations]

Which exposed the issue, they are symbols now. I'm trying to figure out when the change from strings to symbols was made, but I have a branch that makes it workable in 2.3.18 at least.

@openfirmware
Copy link

And the change from strings to symbols comes from using Ruby 1.9.3 instead of Ruby 1.8.7. Maybe the line could then be changed to have a Ruby version dependant condition, or a larger condition:

if respond_to?(:scope) && !protected_methods.include?(:scope) && !protected_methods.include?('scope')

@nertzy
Copy link
Collaborator

nertzy commented Jul 7, 2013

@openfirmware That makes sense. We could also do something like:

if respond_to?(:scope) && !protected_methods.map(&:to_s).include?("scope")

Would you like me to pull in this change and cut a new 0.2.x gem version? Just send a pull request. Or just let me know and I can put it together.

@nertzy nertzy reopened this Jul 7, 2013
openfirmware added a commit to openfirmware/pg_search that referenced this issue Jul 8, 2013
Fixes Casecommons#90, a compatibility issue between Ruby 1.8.7 and Ruby 1.9.3.
@openfirmware
Copy link

Thanks! I just sent a PR with your suggestion.

@nertzy
Copy link
Collaborator

nertzy commented May 4, 2015

Closing this out because it is old and deals with an outdated version of pg_search. Feel free to open a new issue if anything similar comes up again with the latest versions. Thanks!

@nertzy nertzy closed this as completed May 4, 2015
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

3 participants