Skip to content

Replace all uses of SON with dict #2898

@ShaneHarvey

Description

@ShaneHarvey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions