-
Notifications
You must be signed in to change notification settings - Fork 199
sort keys when serializing objects to JSON #92
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
Conversation
@nmarley Thanks so much for adding this functionality! We'd love to merge it, but could you write a quick test for this first? |
Yep, sure! Build failed but it looks like an error w/IPFS that might be resolved if the build is restarted. Otherwise not sure how to proceed. |
I don't have permission in Travis-CI to restart the build. |
I also don't have permission to restart the build, but I think it's failing due to a broken test. Could you try to replicate this error by running the tests with python 3.5 on your machine?
|
@nmarley I was mistaken about not having permission; I was looking on the wrong UI for it. I've restarted the build. Hopefully this will confirm whether the problem is a test or with Travis. |
Okay, everything's good here. Thanks @nmarley for your work! |
@Alexander255 I have some concerns about the seemingly nondeterministic behavior of IPFS here. Any idea what might have made this thing hash differently sometimes (which seems the be the cause of the test failure)? |
Awesome, thanks! |
@nmarley After looking at the unit test I think we should probably use the most compact + reproducible JSON representation available. Doing so should maximize our chances of the resulting hash being identical across different implementations (and also saves some minor space). Thanks for spotting this in the first place, btw! 🙂 @whereswaldon: The CI failure is actually correct and due to a known issue: #85 („Sometimes not all files passed to add() function are added”). We could solve this by getting that issue fixed. 😝 |
Currently the
add_json
method doesn't sort keys before serializing a Python object to JSON.Example script:
Script on node1:
Same script on node2:
Even though the same content was added via
add_json
, the IPFS hashes are different b/c the dict keys weren't sorted when serialized to JSON (note the keys are moved around):