diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-01-20 18:17:36 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-01-20 18:32:27 +0000 |
commit | 30b0e5848c5a91c0bfd1ef33ec4b9bc36bcead0b (patch) | |
tree | 2e8b9f966ce39701ee3b2d1905209acec1f0cc85 /activerecord | |
parent | de41f5a9799cbce276ca9c439c99f4377191b36d (diff) | |
download | rails-30b0e5848c5a91c0bfd1ef33ec4b9bc36bcead0b.tar.gz rails-30b0e5848c5a91c0bfd1ef33ec4b9bc36bcead0b.tar.bz2 rails-30b0e5848c5a91c0bfd1ef33ec4b9bc36bcead0b.zip |
Fix another race condition.
From 2c667f69aa2daac5ee6c29ca9679616e2a71532a.
Thanks @pwnall for the heads-up.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods/read_test.rb | 8 |
3 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index f8815fefc9..a1e34a3aa1 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -1,6 +1,5 @@ require 'active_support/core_ext/enumerable' require 'active_support/deprecation' -require 'thread' module ActiveRecord # = Active Record Attribute Methods @@ -38,8 +37,6 @@ module ActiveRecord def define_attribute_methods # Use a mutex; we don't want two thread simaltaneously trying to define # attribute methods. - @attribute_methods_mutex ||= Mutex.new - @attribute_methods_mutex.synchronize do return if attribute_methods_generated? superclass.define_attribute_methods unless self == base_class diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index c0722e5eeb..e90503d173 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -1,4 +1,5 @@ require 'active_support/concern' +require 'thread' module ActiveRecord module Core @@ -80,6 +81,8 @@ module ActiveRecord end def initialize_generated_modules + @attribute_methods_mutex = Mutex.new + # force attribute methods to be higher in inheritance hierarchy than other generated methods generated_attribute_methods generated_feature_methods diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb index 0df9ffc0c5..764305459d 100644 --- a/activerecord/test/cases/attribute_methods/read_test.rb +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -1,5 +1,6 @@ require "cases/helper" require 'active_support/core_ext/object/inclusion' +require 'thread' module ActiveRecord module AttributeMethods @@ -20,6 +21,13 @@ module ActiveRecord include ActiveRecord::AttributeMethods + def self.define_attribute_methods + # Created in the inherited/included hook for "proper" ARs + @attribute_methods_mutex ||= Mutex.new + + super + end + def self.column_names %w{ one two three } end |