Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

config.active_record.observers breaks rake tasks #4045

Closed
june29 opened this Issue · 8 comments

5 participants

@june29

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

@vijaydev
Collaborator

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

@drogus
Collaborator

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

@drogus drogus closed this
@june29

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
@drogus
Collaborator

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

@june29

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.

@kennyj
Collaborator

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 referenced this issue from a commit in kennyj/rails
@kennyj kennyj Add a testcase for GH #4045 38c9618
@kennyj
Collaborator

@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 ?

@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj
Collaborator

Anyway, I sent the PR #5879 :-)

@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj Testcase for #5847 and #4045. 65fa512
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj Fix #5847 and #4045. Force load AR::Base before loading an applicatio…
…n model.
1e2b7a8
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj Fix #5847 and #4045. Force load AR::Base before loading an applicatio…
…n model.
81af288
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj Fix #5847 and #4045 on master. c0ba0f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.