-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Loading geocoded model in an initializer can cause error with certain dependencies #1318
Comments
Hmm...I see what you're saying, but doesn't this problem lie more with the |
I think if However, it doesn't seem harmful to add a check to ensure I've just stumbled upon a similar issue to this one for the 'newrelic_rpm' gem newrelic/newrelic-ruby-agent#279 |
FYI, I suspect this issue is related: #1178 The https://github.com/reactjs/react-rails/blob/master/lib/react/rails/railtie.rb#L26 It appears that it is down to the order in which the gems are specified in the gemfile as to how the initializers are eventually executed. |
OK, after some more investigation, I think I agree with this. Going to merge. Thanks for your patience! (And the good research.) |
Merged #1317 |
Expected behavior
If I have a model:
I should be able to load the model in an initializer? e.g. for configuration
Actual behavior
Depending on what other gems/initializers you have included in your app, It is possible that at the
TestModel
initializer is run before the Geocoder initializer executes (and inserts theRailtie
intoActiveRecord
)Geocoder initializer:
geocoder/lib/geocoder/railtie.rb
Line 7 in 12dded6
This can cause an
undefined method 'geocoded_by'
error when the application is bootingIt's possible to fix this issue by explicitly including Geocoder in the model:
But I believe the better way to fix this would be to put a constraint on the Geocoder Railtie initializer such that it is forced to run before the application initializers. I can't see any reason why this would be a problem? I've implemented this change in a PR here
Steps to reproduce
Rails loads application initializers together in one group (in alphabetical order), but other initializers and groups of initializers are run after being sorted in topological order. There are some gems that include initializers that will alter the execution order and can therefore delay the Geocoder initializer. (e.g. the
heroku_rails_deflate
gem)Environment info
The text was updated successfully, but these errors were encountered: