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

Undocumented behavior: jsonpatch.compare alters obj1 #93

Open
DavidMikeSimon opened this issue Jan 28, 2016 · 5 comments
Open

Undocumented behavior: jsonpatch.compare alters obj1 #93

DavidMikeSimon opened this issue Jan 28, 2016 · 5 comments
Labels

Comments

@DavidMikeSimon
Copy link

The compare function calls _generate internally, which, in addition to generating a patches array, updates the mirror object to match the obj object! This caught me by surprise and created a bunch of hard-to-debug problems.

Please document this behavior in the API docs, or better yet, allow this behavior to be disabled (since now I have to make lots of deep clones every time I call jsonpatch.compare to keep it from messing with my program state...)

@miyconst
Copy link
Collaborator

cc @tomalec, @Starcounter-Jack

@tomalec
Copy link
Collaborator

tomalec commented Jan 29, 2016

Thanks for pointing that!

I would said that from API purity perspective we should not update mirror object on every (public) compare call, maybe unless explicitly specified.

I think we may consider, if possible, adding a parameter for that.

@warpech
Copy link
Collaborator

warpech commented Jan 29, 2016

Agreed.

Actually we addressed this problem before (there was a PR: #53), so that sounds like a regression.

There is even a test for that: b2435fa#diff-2f9a66403e6f581b7b3abaff2c80ca45R694. Maybe the test is too naive.

@warpech warpech added the bug label Jan 29, 2016
@alshakero
Copy link
Collaborator

alshakero commented Jun 8, 2017

Isn't this fixed by #167?

@tomalec
Copy link
Collaborator

tomalec commented Jun 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants