This project is archived and is in readonly mode.
Rails3: observer in config/application.rb brokes rake db:migrate
Reported by petRUShka | June 28th, 2010 @ 12:38 PM | in 3.0.2
user@linux-equf:~/proj/my_app> rake db:migrate --trace
(in /home/user/proj/my_app)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
No attribute named `status` exists for table `orders`
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/predicate_builder.rb:24:in `build_from_hash'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/query_methods.rb:216:in `map'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/predicate_builder.rb:9:in `each'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/predicate_builder.rb:9:in `map'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/predicate_builder.rb:9:in `build_from_hash'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/query_methods.rb:216:in `build_where'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/relation/query_methods.rb:42:in `where'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/base.rb:405:in `__send__'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/base.rb:405:in `where'
/home/user/proj/my_app/app/models/order.rb:32
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:418:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:418:in `load_file'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:417:in `load_file'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:313:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:455:in `load_missing_constant'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:156:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:154:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:154:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.11/lib/rspec/core/backward_compatibility.rb:26:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.11/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:103:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:102:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:102:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/core_ext/string/conversions.rb:59:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:177:in `observed_class'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:170:in `observed_classes'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:190:in `observed_classes'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:186:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/observer.rb:94:in `initialize'
/usr/lib/ruby/1.8/singleton.rb:94:in `new'
/usr/lib/ruby/1.8/singleton.rb:94:in `instance'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:64:in `instantiate_observer'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:37:in `instantiate_observers'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:37:in `each'
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.0.beta4/lib/active_model/observing.rb:37:in `instantiate_observers'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/railtie.rb:80
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:17:in `instance_eval'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:17:in `execute_hook'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:7:in `on_load'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/railtie.rb:79
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:15:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:15:in `execute_hook'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:24:in `run_load_hooks'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:23:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/lazy_load_hooks.rb:23:in `run_load_hooks'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application/finisher.rb:46
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:25:in `instance_exec'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:25:in `run'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:55:in `run_initializers'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:54:in `each'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:54:in `run_initializers'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application.rb:119:in `initialize!'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application.rb:81:in `send'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application.rb:81:in `method_missing'
/home/user/proj/my_app/config/environment.rb:5
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application.rb:94:in `require_environment!'
/usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/application.rb:192:in `initialize_tasks'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
order.rb, line 32:
scope :old, where(:status => "old")
But if i comment this config line:
config.active_record.observers = :order_observer
rake db:migrate works fine.
Rails3.beta4
ruby 1.8.7 (2008-08-11 patchlevel 72) [i586-linux]
Comments and changes to this ticket
-
Santiago Pastorino June 29th, 2010 @ 01:59 AM
- Tag changed from rails3 observers to arel rails3, rails3 observers, migrations
- State changed from new to open
- Milestone cleared.
- Importance changed from to Low
I've reproduced this
-
Santiago Pastorino June 29th, 2010 @ 02:26 AM
I'm thinking that we need to execute build_* things on ARel just before executing the query.
Also this is going to improve a lot the performance because of the way the current code is cloning every Arel::Relation object just before execute each method.
So perhaps keeping a trace of what to do and do at the end on build_arel and then execute the query i think it would be the best and a solution for that. -
Jeremy Kemper June 29th, 2010 @ 04:11 AM
Workaround:
def self.old() where :status => 'old' end
The root fix is as Santiago suggests: building the relation should be lazy, not loading the table until SQL is actually needed.
-
Michael Koziarski June 29th, 2010 @ 04:24 AM
Alternative work around:
scope :old, lambda { where(:status => "old") }
-
Santiago Pastorino June 29th, 2010 @ 04:56 AM
Another one :P
config.active_record.observers = :order_observer unless File.basename($0) == 'rake'
-
José Valim June 29th, 2010 @ 05:58 PM
- Importance changed from Low to High
Sometime ago we had the same issue and this commit fixed it:
http://github.com/rails/rails/commit/181c414baa877d748671d03fb09499...
It seems that something else is causing the same failure. My suggestion is:
-
Implement the behavior described in the TODO in the commit above, to ensure we won't have other leakage;
-
Add a test to railtie suite;
Notice, that the observer just trigger the model to be loaded earlier triggering the issue. If you are using a plugin that forces all your models to be loaded or an initializer, the same issue would appear (as stated in #5003).
-
Repository June 29th, 2010 @ 06:59 PM
(from [67582f08bf86ec71a27363554bc550e929a007f7]) Push a failing test for issues [#4994] and [#5003]. http://github.com/rails/rails/commit/67582f08bf86ec71a27363554bc550...
-
Repository June 29th, 2010 @ 07:16 PM
- State changed from open to resolved
(from [af6ec607fa9af96569fd2e143147f2dc0ecd583b]) No need to check if the attribute exists (this is the same behavior as in 2.3) [#4994 state:resolved] and [#5003 state:resolved] http://github.com/rails/rails/commit/af6ec607fa9af96569fd2e143147f2...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 5003 default_scope prevents a rake db:migrate if attributes in DB don't exist (from [67582f08bf86ec71a27363554bc550e929a007f7]) Push a ...
- 4994 Rails3: observer in config/application.rb brokes rake db:migrate (from [67582f08bf86ec71a27363554bc550e929a007f7]) Push a ...
- 4994 Rails3: observer in config/application.rb brokes rake db:migrate (from [af6ec607fa9af96569fd2e143147f2dc0ecd583b]) No need...
- 5003 default_scope prevents a rake db:migrate if attributes in DB don't exist (from [af6ec607fa9af96569fd2e143147f2dc0ecd583b]) No need...