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

Report the attribute on ActiveRecord::SerializationTypeMismatch #27773

Merged
merged 1 commit into from Jan 30, 2017

Conversation

@kirs
Copy link
Member

@kirs kirs commented Jan 23, 2017

Today when you get ActiveRecord::SerializationTypeMismatch it doesn't give you a tip about what attribute caused the error. This is not user friendly:

screen shot 2017-01-22 at 22 39 03

I think we should report it together with the error.
Regarding the implementation, I had to catch SerializationTypeMismatch on one level up in Attribute because that's where we know the attribute name. SerializationTypeMismatch is raised from a coder that has no idea about the attribute name.

@sgrif @kaspth

@rails-bot
Copy link

@rails-bot rails-bot commented Jan 23, 2017

r? @chancancode

(@rails-bot has picked a reviewer for you, use r? to override)

@maclover7
Copy link
Member

@maclover7 maclover7 commented Jan 23, 2017

Please take a look at the Travis CI build when you get a chance.

@eileencodes
Copy link
Member

@eileencodes eileencodes commented Jan 23, 2017

@maclover7 the failure isn't related to this branch, it's failing on all new PRs. Something on the env side got updated.

activerecord/lib/active_record/errors.rb Outdated
@value = value
end

def to_s

This comment has been minimized.

@kaspth

kaspth Jan 23, 2017
Member

Generally I'd expect message to hold this for an exception. Why are we using to_s?

activerecord/lib/active_record/attribute.rb Outdated
@@ -37,6 +37,9 @@ def value
# `defined?` is cheaper than `||=` when we get back falsy values
@value = type_cast(value_before_type_cast) unless defined?(@value)
@value
rescue ActiveRecord::SerializationTypeMismatch => error
error.attribute = name

This comment has been minimized.

@kaspth

kaspth Jan 23, 2017
Member

Mutating the error is a bit of a smell to me. And, like you said, having the top level attribute know about this error seems off too.

We need to find some other way to extract this. Maybe there's some way of making the YAMLColumn aware of the attribute (or just it's column name) when it's instantiated?

Topic.serialize :content, Hash
topic = Topic.create!(content: { zomg: true })

Topic.serialize :content, Array

This comment has been minimized.

@kaspth

kaspth Jan 23, 2017
Member

Won't this leak into other tests?

@kirs
Copy link
Member Author

@kirs kirs commented Jan 29, 2017

@kaspth thanks for review! I updated the code. Now YAMLColumn accepts attribute name.

@rafaelfranca rafaelfranca merged commit 6bf6957 into rails:master Jan 30, 2017
2 checks passed
2 checks passed
codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@maclover7 maclover7 removed the needs work label Jan 30, 2017
@kirs
Copy link
Member Author

@kirs kirs commented Jan 31, 2017

cc @jules2689

kamipo added a commit that referenced this pull request Jun 30, 2020
`attr_name` in `YAMLColumn` is not part of v1 YAML.

Ref #27773.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.