-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
PyMongo's bson api originally added SON to deal with the fact that, at the time, Python dictionaries were unordered and OrderedDict was not yet in the stdlib. SON was implemented to ensure documents could maintain a consistent field order. Starting in Python 3.7, dictionaries are guaranteed to be ordered:
the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec.
https://docs.python.org/3/whatsnew/3.7.html#summary-release-highlights
Fast forward to today, pymongo and mongoengine only support Python 3.9+ so SON really has no benefit over dict. Using SON is actually a detriment because it requires more memory and CPU overhead than dict. Therefore, we should consider replacing all uses of SON with dict. This can be considered a breaking change because SON has a few methods which dict does not (has_key(), iterkeys(), and itervalues()) but many (most?) apps don't use these method and won't notice a difference.