Chris Cruft
2009-Nov-07 20:53 UTC
Fix nested attribute error messages introduces new requirement -on purpose?
This commit (f5f7c40f3aedf88b2aef4e83602a4f41ffa5d0ab) introduces a
new limitation for ActiveRecord::Base instances that has (to my
knowledge) never been discussed.
Briefly: an error on an attribute cannot be set as the result of an
exception computing the value of the attribute.
For example:
def v
compute_it
rescue
errors.add(:v, "Dadgummit")
end
After the aforementioned commit, when compute_it raise an exception,
ActiveRecord::Error#initialize references v, which in turn raises
another exception, which adds another error, which in turn proves that
my stack is not infinitely deep.
Is it reasonable to assume that ActiveRecord::Error instances can
reference its erroneous attribute''s value? If so, the above pattern
won''t work and instead a sentinel value will need to be set (U-G-L-Y).
You can see the background of this commit on ticket #3147 here:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3147