-
Notifications
You must be signed in to change notification settings - Fork 59
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
OrderedDicts do not guarantee ordering on decode #66
Comments
What's even worse is that "Canonical" encoding requires that CBOR map keys be in a specific order. I think for cross language interoperability |
I wrote up a proposal that we grab tag 272 for this: |
Python dicts have formally guaranteed ordering since 3.7 (released 2018) and informally since 3.6 (released 2015). 3.6 and older are long out of any support, even 3.7 only gets security support until the end of the month (2023-06-27). As long as the entries are encoded in-order and cbor2 then rehydrates the dict in that order, the resulting dict will preserve the original ordering. Then again, cbor itself does not guarantee the ordering preservation of maps, and lots of languages don't maintain ordering of the default map type (some going as far as to intentionally scramble it). |
When I opened this I was stuck on Python 3.5 due to a large dependency that was very opinionated about Python version. That's now since been resolved. Regardless, the semantic difference between an ordered and unordered map is important, largely for other languages where the map implementation may or may not choose to preserve ordering information. |
When decoding a map that was encoded as an
OrderedDict
, the resulting map is a standard pythondict
which does not guarantee ordering. I don't believe ordered maps are part of RFC 7049, but it may make sense to simply always return anOrderedDict
(maybe as a flag onCBORDecoder
init) instead ofdict
given that they should be always be decoded in the order they were encoded in.The text was updated successfully, but these errors were encountered: