Skip to content
Browse files

Ignore all exceptions for validates_acceptance_of columns fetch so it…

… can run even without a database connection

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 4d9a7ab commit ea609b265ffc30cac00bf09a262027f96964ed6f @tarmo tarmo committed with NZKoz Sep 26, 2008
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/validations.rb
View
2 activerecord/lib/active_record/validations.rb
@@ -472,7 +472,7 @@ def validates_acceptance_of(*attr_names)
db_cols = begin
column_names
- rescue ActiveRecord::StatementInvalid
+ rescue Exception # To ignore both statement and connection errors
[]
end
names = attr_names.reject { |name| db_cols.include?(name.to_s) }

2 comments on commit ea609b2

@Manfred

I’m not sure catching Exception is such a good idea, it might mask all kinds of bugs like syntax errors thrown while executing the column_names method.

Why not just catch the errors thrown by ActiveRecord?

@NZKoz
Ruby on Rails member
NZKoz commented on ea609b2 Sep 26, 2008

Yeah, it’s definitely less than ideal, but the problem is the variety of exceptions that get thrown when this thing is missing. There’s one for each of the adapters, and several different ones depending on the ‘backing gem’ i.e. pg vs postgres.

Hopefully for 2.3 we can tidy the boundaries between adapter and driver and make sure that only AR errors are thrown by the Adapters, but right now that line’s too fuzzy and making a far reaching change for this one case didn’t quite seem worth it.

Please sign in to comment.
Something went wrong with that request. Please try again.