Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

config.active_record.observers breaks rake tasks #4045

Closed
june29 opened this Issue Dec 20, 2011 · 8 comments

Comments

Projects
None yet
5 participants

june29 commented Dec 20, 2011

When I set config.active_record.observers in config/application.rb, that breaks rake tasks.
See more detail : https://gist.github.com/597695

Member

vijaydev commented Dec 20, 2011

Why is Account class defined in account_observer.rb ? Isn't the error message clear about this?

Member

drogus commented Dec 20, 2011

Yup, this is not a problem with rails, please move your model to app/models/account.rb

@drogus drogus closed this Dec 20, 2011

june29 commented Dec 20, 2011

Sorry, that example is not good.
I prepared another example to come out the problem.

Can you check again?
https://gist.github.com/1501347

@drogus drogus reopened this Dec 20, 2011

Member

drogus commented Dec 20, 2011

@june29 can you try newest 3.0.x release? I would like to confirm that this still exists before trying to fix.

june29 commented Dec 20, 2011

First, I met this problem with Rails 3.1.1.
Then I tried Rails 3.2.0.rc1 and Rails 3.0.10, met same problem.

Contributor

kennyj commented Dec 20, 2011

I reproduced it (june29's step).
I think that it is circular reference (loading) problem.

  1. The rake task loads User model.
  2. ActiveRecord::Base is loaded.
  3. ActiveRecord's railtie is loaded.
  4. Railtie call instance_observers method.
  5. UserObserver is loaded.
  6. UserObserver loads User ★ error !

BTW, the following task is work fine.

require 'active_record/base' # added

namespace :user do
  desc "count user"
  task :count => :environment do
    p User.count
  end
end

@kennyj kennyj added a commit to kennyj/rails that referenced this issue Jan 4, 2012

@kennyj kennyj Add a testcase for GH #4045 38c9618
Contributor

kennyj commented Jan 4, 2012

@josevalim @drogus

I added a testcase (38c9618) for this issue,
and I tought a plan to fix (85a6511) .

This solution is ActiveRecord::Base loaded to force.
But it seems that the solution is not properly ?

Do you have any idea ?

Contributor

kennyj commented Apr 17, 2012

Anyway, I sent the PR #5879 :-)

@kennyj kennyj added a commit to kennyj/rails that referenced this issue Apr 24, 2012

@kennyj kennyj Testcase for #5847 and #4045. 65fa512

@kennyj kennyj added a commit to kennyj/rails that referenced this issue Apr 24, 2012

@kennyj kennyj Fix #5847 and #4045. Force load AR::Base before loading an applicatio…
…n model.
1e2b7a8

@kennyj kennyj added a commit to kennyj/rails that referenced this issue Apr 26, 2012

@kennyj kennyj Fix #5847 and #4045. Force load AR::Base before loading an applicatio…
…n model.
81af288

@jonleighton jonleighton added a commit that referenced this issue Apr 26, 2012

@jonleighton jonleighton Merge pull request #5995 from kennyj/fix_5847-3
Fix #5847 and #4045. Load AR::Base before loading an application model.
8cd14c0

@kennyj kennyj added a commit to kennyj/rails that referenced this issue May 29, 2012

@kennyj kennyj Fix #5847 and #4045 on master. c0ba0f0

@josevalim josevalim added a commit that referenced this issue May 29, 2012

@josevalim josevalim Merge pull request #6518 from kennyj/fix_5847-4
(Try again) Fix #5847 and #4045.
9fa3926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment