-
Notifications
You must be signed in to change notification settings - Fork 226
Add sort_keys parameter to Packer for stable dict packing. #164
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
Same as for simplejson, allows reproducible serialization of dictionaries.
In msgpack, sort_keys doesn't enough for "canonicalize". There are some valid serialization for same data. msgpack-python is too complex already. |
This whole repository is a "python only" feature, since it is a python package. You claim compatibility with simplejson. It is impossible to add new features without adding complexity, the question is whether the feature is useful enough to justify it. |
You're right. |
|
But msgpack is cross-language format. I don't want to add feature only for comparing two Python data. |
You cannot compare JSON files either because you don't know if Yet the option exists and is useful. So one can serialize in a way that at least the same code (or number of compatible codes) will always produce the same output. The fact that it may not be always possible should not be a reason for dismissal. BTW this PR is not called "canonicalize", it is called "sort_keys". |
Even so,
Same version of same encoder is required. And if you have trouble, investigating it is very hard.
If canonicalize is not purpose, how |
bencode may be stable serialize format. How about it? |
I was under the impression that msgpack and this package are advertised as a drop-in replacement of json. Python json package supports sort_keys, msgpack doesn't.
Canonicalize implies universality, which as you correctly pointed out is impossible. It is not standardized and even if it was, it would be not mandatory therefore one cannot rely on it.
For bencode stability is not just useful it is crucial and mandatory. That is not possible for msgpack since one cannot be |
I don't advertise this project as complete drop-in replacement.
I don't recommend to use msgpack for unittest since msgpack is less human readable.
It can disturb optimization in the future. For example, it makes more hard to reimplement in C instead of Cython. Additionally, people may misuse the option and ask "Why my code doesn't work?". |
Not recommend and make it impossible are two different things. Libraries are supposed to give people options, because one can misuse pretty much anything anyway. I can hardly argue with what may happen in the future or what people may ask or how they may misuse the code. Anything can happen, but most of this things are unlikely to happen. |
CESU-8 and tail call optimization are not supported by Python since Python doesn't recommend them.
Only when "how to use the option in right way" is easy to explain. |
There are idea relating to your idea. I'll discuss about:
Until consensus built, I think msgpack shouldn't support it. |
I read the spec again. The wording is not 100% clear, but since the same language is used for both arrays and maps, it is logical to assume that maps in msgpack are ordered sequences.
In this light, I would say that msgpack-python is misusing msgpack format to store unordered python dictionaries in ordered map type. And even worse So until msgpack has unordered map type, To clarify ordered property I created an issue msgpack/msgpack#210 |
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538 Part of #5652
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3] and changes in test-run's commit 853c9532c56e523da68030a1b7956c2e753b917e "python3: fix printing of called box command". 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538 Part of #5652
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5562 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5562 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538 (cherry picked from commit 45972c9)
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538 (cherry picked from commit 45972c9)
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538 (cherry picked from commit 45972c9)
Response object is a unpacked msgpack structure, returned by Tarantool. Nor msgpack-python [1] that used in tarantool-python nor msgpack [2] itself cannot guarantee an order of keys in unpacked dictionaries. Therefore we have different keys order with running tests under Python 2 and Python 3, for example box-py/call.test.py. To workaround a problem proposed a conversion of dictionaries in a tuple to lists before printing Response object. Requires changes in tarantool-python [3]. 1. msgpack/msgpack-python#164 2. msgpack/msgpack#215 3. tarantool/tarantool-python#186 Part of #5652 Follows up #5538 (cherry picked from commit 45972c9)
It is often useful to have reproducible serialization. It allows, for instance, efficient comparison of records coming from different sources.
simplejson provides an option sort_keys, which makes serialization of dictionaries reproducible. This patch adds the same option to msgpack Packer class.