Skip to content

feat: unpin pymongo and upgrade to 4.19.0 - #39246

Draft
feanil wants to merge 2 commits into
masterfrom
feanil/upgrade-pymongo
Draft

feanil wants to merge 2 commits into
masterfrom
feanil/upgrade-pymongo

Conversation

@feanil

@feanil feanil commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Removes the pymongo<4.4.1 constraint and re-locks, which takes pymongo from 4.4.0 to 4.19.0. Nothing else in the lock moves.

The pin came from the 3.x to 4.4.0 upgrade in #35179. It froze the driver at the version that had been tested and did not record an incompatibility with anything newer. I went through the pymongo changelog from 4.4 to 4.19 and none of the removals touch APIs we use: https://github.com/mongodb/mongo-python-driver/blob/master/doc/changelog.rst. The one operational change is that pymongo 4.18 dropped MongoDB 4.2, so the driver now needs MongoDB 4.4+. CI and Tutor already run MongoDB 7.

Verified locally against mongo:7 with Python 3.12: the xmodule modulestore, contentstore and split_modulestore_django tests under lms settings, the Studio contentstore, asset and import/export tests under cms settings, and the structures_pruning tests including the normally-skipped TestSplitMongoBackend class.

Not in this PR: three call sites still use APIs that pymongo 4.0 removed, so they have been broken since 4.4.0 and this change does not affect them. Collection.remove is called in xmodule/contentstore/mongo.py from _drop_database and from remove_redundant_content_for_courses, which backs the cleanup_assets management command. common/djangoapps/track/backends/mongodb.py calls ensure_index and insert(manipulate=False). Their tests are either skipped or mock the client, which is why CI did not catch them. I'll handle those separately.

Closes #35265

feanil and others added 2 commits October 16, 2026 17:09
The `pymongo<4.4.1` constraint was added in the 2024 upgrade from 3.x to
4.4.0 (#35179) to freeze the
driver at the version that had been tested.  It did not record a known
incompatibility with later 4.x releases, and nothing in the pymongo
changelog between 4.4 and 4.19 removes an API this codebase uses:
https://github.com/mongodb/mongo-python-driver/blob/master/doc/changelog.rst

Drop the constraint from the hand-maintained `[tool.edx_lint]`
uv_constraints lists in the root project and the structures_pruning
script, regenerate the derived `constraint-dependencies`, and re-lock
with `make upgrade-package package=pymongo`.  Only pymongo moves; no
other locked package changes.

Operational note: pymongo 4.11 dropped MongoDB 3.6, 4.14 dropped 4.0 and
4.18 dropped 4.2, so the driver now requires MongoDB 4.4+.  CI and Tutor
already run MongoDB 7.

Closes #35265

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pymongo 4.9 added a ResourceWarning when a MongoClient is garbage
collected without being closed, and these tests were the only ones in
the modulestore and contentstore suites that triggered it under `-Wd`
after the upgrade to 4.19.0.  Register the close as a cleanup so the
warnings tracker stays quiet.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unpin pymongo in edx-platform

1 participant