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

Pass class name to Sequel::MassAssignmentRestriction error #2079

Closed

Conversation

artofhuman
Copy link
Contributor

If the instance has a class name, pass this name to the error message to better understand the error in monitoring systems such as Sentry.

If the instance has a class name, pass this name to the error
message to better understand the error in monitoring systems such as Sentry.
@jeremyevans
Copy link
Owner

Instead of including the model class name in the message, we should add a method to set the model instance as an instance variable in the exception. That takes less work, and still allows the rescuer to get the class name. This should be implemented using a class method on MassAssignmentRestriction, which the callers can use.

@artofhuman
Copy link
Contributor Author

Added @model instance variable to MassAssignmentRestriction, similar to ValidationFailed

# The Sequel::Model object related to this exception.
attr_reader :model

def initialize(msg, model)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not backwards compatible, and will break code that uses raise MassAssignmentRestriction. I recommend using a different class method, such as create.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to make model arg optional?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a separate method.

attr_reader :model

def self.create(msg, model)
@model = model
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the instance variable on the class, not on the created instance. You don't catch this because you only test for the message and not for the model value. The tests should be updated to test that the model is set correctly.

@jeremyevans
Copy link
Owner

Thanks for continuing to work on this. I'll try to merge and clean this up on Monday.

@jeremyevans
Copy link
Owner

Squash merged at 1e00c84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants