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

Fixed a bug where AR::RecordNotSaved loses the given error message #17808

Conversation

yuki24
Copy link
Contributor

@yuki24 yuki24 commented Nov 28, 2014

This was extracted from #17806 that had an improvement and a bug fix. This is the bug fix.

Since 3e30c5d, AR::RecordNotSaved started ignoring the given error message. This commit changes AR::RecordNotSaved#initialize to not ignore the given error message.

Doing create_or_update || raise(RecordNotSaved.new(nil, self)) in ActiveRecord::Persistence looks weird, but I'll send another pull request to improve it as soon as this one is merged.

cc @arthurnn

Since 3e30c5d, it started ignoring the given error message. This commit
changes the behavior of AR::RecordNotSaved#initialize so that it no
longer loses the given error message.
@arthurnn
Copy link
Member

yeah.. this make sense 👍

@@ -54,9 +54,9 @@ class RecordNotFound < ActiveRecordError
class RecordNotSaved < ActiveRecordError
attr_reader :record

def initialize(record)
def initialize(message, record = nil)
Copy link
Member

Choose a reason for hiding this comment

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

Is there any place we don't pass record?

Copy link
Member

Choose a reason for hiding this comment

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

Just saw that there are. I think we should always pass record

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that there are several questions around whether or not we should always include record:

I guess we should focus on a bug fix in this pull request as @arthurnn suggested earlier, and we can discuss the questions above after that.

@arthurnn @rafaelfranca what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I guess it is fine as it is now.

@rafaelfranca rafaelfranca added this to the 4.2.0 milestone Nov 28, 2014
rafaelfranca added a commit that referenced this pull request Nov 28, 2014
…loses-error-message

Fixed a bug where AR::RecordNotSaved loses the given error message
@rafaelfranca rafaelfranca merged commit 2cdd229 into rails:master Nov 28, 2014
@yuki24 yuki24 deleted the fix-bug-where-record-not-saved-loses-error-message branch November 28, 2014 15:56
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