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

Multiple serializions and deserializations lead to duplications #107

Open
onemanstartup opened this issue Feb 24, 2014 · 3 comments
Open

Comments

@onemanstartup
Copy link

After second deserialization for example it doubles counts like for example there were 10 items Item.all.count #=> 10 and after deserialization it's 20. And every item is with the same ids.
Why it can be?

P.S. it seems there is no dup method like in activerecord to create shallow copy of object. Is it needed in library?

@sxross
Copy link
Owner

sxross commented Feb 24, 2014

Ok, I have a repro case. Let me look into this. I assume the desired behavior is that the contents of the in-memory store, dirty or not, is discarded in favor of the data being deserialized. Would that be your understanding?

@sxross
Copy link
Owner

sxross commented Feb 24, 2014

I'd like to understand the use case for this a bit better. The typical usage is to deserialize on launch and then serialize on change. So the second deserialization would typically not happen unless the app were evicted from memory or crashed. In those cases, the data store would begin empty and no dups would appear.

Is there a different use case where multiple deserializations are necessary?

@onemanstartup
Copy link
Author

Here is the repo https://github.com/onemanstartup/motion_model_possible_bug

First count is 0
Count after serialize is 1
Item id is 2
Item id is 2
Item id is 2
Item id is 2
Item id is 2
Count after two deserialization is 5
 [FAILED - 5.==(1) failed]

The same behaviour can be replicated in repl.
Desired behaviour is so after deserialization I can't have duplicate not unique items.
Maybe it is not a bug. Before that i make this code
https://github.com/onemanstartup/motion_model_possible_bug/blob/master/app/item.rb#L7-L12
so attrs = self.attributes without dup caused problem of empty association, and trying debugging that i stumped with this deserialization in repl. Now it seems it is not right to call multiple times deserialization, but behaviour is not clear and possible can lead to bugs.

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

2 participants