-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pass class name to Sequel::MassAssignmentRestriction error #2079
Conversation
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.
33e2558
to
51de3cf
Compare
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 |
fe16f0b
to
5ab8426
Compare
Added |
lib/sequel/model/exceptions.rb
Outdated
# The Sequel::Model object related to this exception. | ||
attr_reader :model | ||
|
||
def initialize(msg, model) |
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.
This is not backwards compatible, and will break code that uses raise MassAssignmentRestriction
. I recommend using a different class method, such as create
.
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.
Maybe better to make model arg optional?
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.
I would prefer a separate method.
lib/sequel/model/exceptions.rb
Outdated
attr_reader :model | ||
|
||
def self.create(msg, model) | ||
@model = model |
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.
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.
840e72c
to
fbad090
Compare
Thanks for continuing to work on this. I'll try to merge and clean this up on Monday. |
Squash merged at 1e00c84 |
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.