Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Comments

Projects
None yet
5 participants

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]}

I'm watching the same behaviour in my code.

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.

Contributor

TylerRick commented Nov 5, 2012

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

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.

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.

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 Dec 21, 2012

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] }
Collaborator

batter commented Dec 1, 2014

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

paper_trail - 3.0.6
activerecord - 3.2.13

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.

Ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment