Skip to content
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

Merged
merged 1 commit into from
Mar 2, 2015
Merged

Follow-up to #10776 #19077

merged 1 commit into from
Mar 2, 2015

Conversation

robin850
Copy link
Member

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.

'ActiveModel::AttributeAssignment::UnknownAttributeError'
)
# Raised when unknown attributes are supplied via mass assignment.
class UnknownAttributeError < ActiveModel::UnknownAttributeError
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member Author

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.
sgrif added a commit that referenced this pull request Mar 2, 2015
Move `UnknownAttributeError` to a more sane namespace
@sgrif sgrif merged commit c0584ea into rails:master Mar 2, 2015
@robin850 robin850 deleted the unknown-attribute-error branch March 2, 2015 16:22
rthbound added a commit to rthbound/rails that referenced this pull request Feb 9, 2016
  - 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants