Permalink
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...
tarmo authored and NZKoz committed Sep 26, 2008
1 parent 4d9a7ab commit ea609b265ffc30cac00bf09a262027f96964ed6f
Showing with 1 addition and 1 deletion.
  1. +1 −1 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

This comment has been minimized.

Show comment
Hide comment
@Manfred

Manfred Sep 26, 2008

Contributor

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?

Contributor

Manfred replied Sep 26, 2008

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

This comment has been minimized.

Show comment
Hide comment
@NZKoz

NZKoz Sep 26, 2008

Member

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.

Member

NZKoz replied 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.