-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Follow-up to #10776 #19077
Follow-up to #10776 #19077
Conversation
'ActiveModel::AttributeAssignment::UnknownAttributeError' | ||
) | ||
# Raised when unknown attributes are supplied via mass assignment. | ||
class UnknownAttributeError < ActiveModel::UnknownAttributeError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than subclassing, let's just alias. There's no reason to have two separate exception classes.
UnknownAttributeError = ActiveModel::UnknownAttributeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aliasing is a little confusing because you would expect error.class.to_s
to return ActiveRecord
exception but it is not. It will cause confusion at least in all bug notification services. I vote for deprecation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdan : We decided to finally alias the constant as there was no big deal ; furthermore, we are already raising errors with constants nested under ActiveModel so having it in the output of error.class.to_s
is not that unexpected.
The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
Move `UnknownAttributeError` to a more sane namespace
- Corrects an incorrect exception message when using accepts_nested_attributes_for - Removes rescue/reraise behavior introduced in rails#19077 - Adds has_many & has_one, nested_attributes test case specifying the message that should be conveyed with an exception raised because one of the nested attributes provided is unknown
Hello,
This pull request is a follow up to #10776.
The name
ActiveModel::AttributeAssignment::UnknownAttributeError
is too implementation specific so let's move the constant directly under the ActiveModel namespace.Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
I don't know whether monkey-patching
_assign_attribute
is the right solution to raise the correct constant so let me know if I should change it.Have a nice day.