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

Zeroes in decimal columns erroneously showing up in changeset #169

Closed
dwwoelfel opened this issue Aug 23, 2012 · 11 comments
Closed

Zeroes in decimal columns erroneously showing up in changeset #169

dwwoelfel opened this issue Aug 23, 2012 · 11 comments
Milestone

Comments

@dwwoelfel
Copy link

If I have a column with a zero value and I update that decimal column to zero again, paper trail creates a new version with changeset [0.0 => 0.0]

Example:

> m = MyModel.create(:my_decimal_column => 0)
> m.versions.last.changeset
=> {}
> m.update_attributes(:my_decimal_column => 0)
> m.versions.last.changeset
=> {"my_decimal_column"=>[0.0, 0.0]}
@rubennorte
Copy link

I'm watching the same behaviour in my code.

@batter
Copy link
Collaborator

batter commented Nov 5, 2012

I believe this is directly related to the serialization issue raised by pull #180, and I'm going to try to merge that in before the next release.

@TylerRick
Copy link
Contributor

IIRC, ActiveRecord's type_cast code is separate from full-blown serializers, so #180 may not fix this, but maybe...

@batter
Copy link
Collaborator

batter commented Nov 6, 2012

Any chance one of you guys could provide a failing test? I attempted to write a failing test for this use case but wasn't able to do it.

@batter
Copy link
Collaborator

batter commented Dec 17, 2012

@dwwoelfel, @rubennorte - What version of rails were you using when you encountered this problem? I believe this issue has been fixed by a change in rails now. If you attempt to call update_attributes on a column, and values are passed in that are no different from what is currently stored on the model, then true gets returned, but a call to the database is not made.

I haven't done a complete thorough investigation, but I believe this change in behavior exists in rails >= 3.0. I tried to reproduce this issue using rails 3.0.2 and was unable to do so. This would lead me to believe that this bug shouldn't be encountered with PaperTrail >= 2.0.0, because those versions have a dependency on rails >= 3.

@batter
Copy link
Collaborator

batter commented Dec 21, 2012

Did some further investigation, with thanks to @TylerRick, looks like this issue should be addressed by ActiveRecord's TypeCasting code. This can be seen in ActiveRecord::ConnectionAdapters::Column. Unless someone can provide a failing test, it appears this one can be closed.

@batter batter closed this as completed Dec 21, 2012
@kevintraver
Copy link

I just noticed this issue still exists. Specifically when using quotes:

> model.update_attributes(:my_decimal_column => '0.0')
> model.versions.last.changeset
=> { "my_decimal_column" => [0.0, 0.0] }

@batter
Copy link
Collaborator

batter commented Dec 1, 2014

@kevintraver - What versions of ActiveRecord and PaperTrail are you using?

@kevintraver
Copy link

paper_trail - 3.0.6
activerecord - 3.2.13

@batter
Copy link
Collaborator

batter commented Dec 3, 2014

@kevintraver - Looks like this may be expected behavior, see rails/rails#17537. At any rate, I'm fairly certain this is not an issue of PaperTrail doing something wrong.

@kevintraver
Copy link

Ok, thanks

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

No branches or pull requests

5 participants