Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3642

pymongo bundles bson as a non-package and stops bson installed as a package

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 4.3.3
    • Component/s: BSON, Packaging
    • None

      pymongo contains multiple top-level directories in the wheel package, which pip simply dumps into the site packages directory, which stomps existing packages with the same name and breaks them in an untraceable way.

      Steps to reproduce.

      1. Install bson:

       pip install bson

      This will install some version of bson, like 0.5.10 on Windows at this point for Python 3.10.

      2. Go to site packages, whether it's global or in a venv directory, and make a copy of the bson directory.

      3. Install pymongo:

       pip install pymongo

      4. Compare the copied bson directory with the one after the step above and you will see bson significantly modified.

      gridfs is installed the same way, but I suppose it can be viewed as an internal Mongo DB project and is less likely to get in the way, but bson is often used on its own to create ObjectId values without having Mongo DB in components that generate those IDs, but otherwise have no DB functionality, and having to inject something like from pymongo.collection import ObjectId makes those components coupled with the database, even though they have nothing to do with it.

      Yes, it is possible to import from bson installed by pymongo, but it seems that some type checkers are confused by this because there is no actual bson package installed. That is, if you skip installing bson and just install pymongo, then run pip show bson and it will tell you that bson is not installed, even though it can be imported. This makes it hard to track versions and functionality.

      Perhaps a namespace package could be used here to split database layer from BSON, or, maybe, there should be a distinct MongoDB-BSON package, so it can be distinguished from the official BSON package. Either way, other packages shouldn't be mangled by pymongo, even those that are as intrinsic to it as bson.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            cis74633@bell.net Andre M
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: