Skip to content

MongoDB: Update adapter to pymongo 4.9#278

Draft
amotl wants to merge 1 commit intomainfrom
pymongo-adapter-4.9
Draft

MongoDB: Update adapter to pymongo 4.9#278
amotl wants to merge 1 commit intomainfrom
pymongo-adapter-4.9

Conversation

@amotl
Copy link
Copy Markdown
Member

@amotl amotl commented Sep 26, 2024

pymongo 4.9 has been released, and includes a few breaking API changes after adding an asynchronous variant to the driver.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 21, 2026

Walkthrough

Update PyMongo adapter internals to new PyMongo 4.9+ module paths and helper names, bump optional pymongo constraint to >=4.9.1,<4.10, and remove a PyMongo-version conditional import-time skip in tests.

Changes

Cohort / File(s) Summary
Adapter — API patch targets
cratedb_toolkit/adapter/pymongo/api.py
Updated patch target strings to use pymongo.synchronous.mongo_client... for internal no-op overrides (_ensure_session, _ClientConnectionRetryable._get_server).
Adapter — Cursor helpers & cursor constants
cratedb_toolkit/adapter/pymongo/cursor.py
Switched imports and helper calls from pymongo.helperspymongo.helpers_shared, and from pymongo.cursor constants to pymongo.cursor_shared. Adjusted usages of _fields_list_to_dict, _index_list, _index_document, and hint handling (wrap non-string hints in SON(...)).
Dependency constraint
pyproject.toml
Changed optional-dependencies.pymongo spec from an upper-bound (pymongo<4.9) to a version window pymongo>=4.9.1,<4.10.
Tests
tests/adapter/test_pymongo.py
Removed verlib2.Version import and the module-level PyMongo-version conditional pytest.skip(...), so the test module no longer skips at import time based on pymongo version.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • surister
  • bmunkholm

Poem

🐰 I hopped through modules, swift and cheery,
Swapped old paths for names less weary,
Helpers shared and sync clients found,
Version bumped — a tidy bound,
A carrot-coded shuffle, light and merry! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main objective: updating the MongoDB adapter to support pymongo 4.9, which aligns with all the changes made.
Description check ✅ Passed The description accurately captures the purpose of the PR: pymongo 4.9 has breaking API changes due to adding async support, and the changes adapt the codebase accordingly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pymongo-adapter-4.9

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cratedb_toolkit/adapter/pymongo/cursor.py (1)

137-137: Clarify boolean chaining on Line 137 to avoid precedence ambiguity.

This currently relies on and/or chaining and is harder to read and lint-clean.

♻️ Proposed change
-            self.__ordering = sort and helpers_shared._index_document(sort) or None
+            self.__ordering = helpers_shared._index_document(sort) if sort else None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cratedb_toolkit/adapter/pymongo/cursor.py` at line 137, Replace the
boolean-chained assignment to self.__ordering that uses "and/or" with an
explicit conditional to avoid precedence ambiguity: when sort is truthy call
helpers_shared._index_document(sort) and assign that result to self.__ordering,
otherwise assign None; locate the expression using self.__ordering and
helpers_shared._index_document in the class (the line that currently reads
self.__ordering = sort and helpers_shared._index_document(sort) or None) and
implement the clearer conditional form.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cratedb_toolkit/adapter/pymongo/cursor.py`:
- Line 137: Replace the boolean-chained assignment to self.__ordering that uses
"and/or" with an explicit conditional to avoid precedence ambiguity: when sort
is truthy call helpers_shared._index_document(sort) and assign that result to
self.__ordering, otherwise assign None; locate the expression using
self.__ordering and helpers_shared._index_document in the class (the line that
currently reads self.__ordering = sort and helpers_shared._index_document(sort)
or None) and implement the clearer conditional form.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 12b2e09d-9bc7-4193-aef7-c23651cbc2dd

📥 Commits

Reviewing files that changed from the base of the PR and between 5c031f0 and 8dc0fcc.

📒 Files selected for processing (3)
  • cratedb_toolkit/adapter/pymongo/api.py
  • cratedb_toolkit/adapter/pymongo/cursor.py
  • pyproject.toml

@amotl amotl force-pushed the pymongo-adapter-4.9 branch 2 times, most recently from 7f34883 to 5c7adf6 Compare March 24, 2026 22:28
pymongo 4.9 has been released, and includes a few breaking API changes
after adding an asynchronous variant to the driver.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
cratedb_toolkit/adapter/pymongo/cursor.py (2)

1-1: Typo in comment.

"Compansate" should be "Compensate".

-# Compansate pymongo<>4.9 woes.
+# Compensate pymongo 4.9 woes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cratedb_toolkit/adapter/pymongo/cursor.py` at line 1, Fix the typo in the
top-line comment that reads "Compansate pymongo<>4.9 woes." by changing
"Compansate" to "Compensate" so the comment reads "Compensate pymongo<>4.9
woes."; locate and update that exact string in
cratedb_toolkit/adapter/pymongo/cursor.py.

137-137: Add parentheses to clarify operator precedence.

Static analysis flags this expression for unclear precedence. While it works correctly, adding parentheses improves readability.

♻️ Suggested fix
-            self.__ordering = sort and helpers_shared._index_document(sort) or None
+            self.__ordering = (sort and helpers_shared._index_document(sort)) or None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cratedb_toolkit/adapter/pymongo/cursor.py` at line 137, The expression
setting self.__ordering uses mixed boolean operators with unclear precedence;
change the assignment in the Cursor class so the result of "sort and
helpers_shared._index_document(sort)" is evaluated first by adding parentheses
around that subexpression before applying "or None" (i.e., wrap the
sort-and-call part), referencing the existing symbol self.__ordering and
helpers_shared._index_document to locate and update the line.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cratedb_toolkit/adapter/pymongo/cursor.py`:
- Line 1: Fix the typo in the top-line comment that reads "Compansate
pymongo<>4.9 woes." by changing "Compansate" to "Compensate" so the comment
reads "Compensate pymongo<>4.9 woes."; locate and update that exact string in
cratedb_toolkit/adapter/pymongo/cursor.py.
- Line 137: The expression setting self.__ordering uses mixed boolean operators
with unclear precedence; change the assignment in the Cursor class so the result
of "sort and helpers_shared._index_document(sort)" is evaluated first by adding
parentheses around that subexpression before applying "or None" (i.e., wrap the
sort-and-call part), referencing the existing symbol self.__ordering and
helpers_shared._index_document to locate and update the line.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 10e6dd9d-2408-47fe-9cd0-ddcc5bdce9ed

📥 Commits

Reviewing files that changed from the base of the PR and between 8dc0fcc and 5c7adf6.

📒 Files selected for processing (4)
  • cratedb_toolkit/adapter/pymongo/api.py
  • cratedb_toolkit/adapter/pymongo/cursor.py
  • pyproject.toml
  • tests/adapter/test_pymongo.py
💤 Files with no reviewable changes (1)
  • tests/adapter/test_pymongo.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • cratedb_toolkit/adapter/pymongo/api.py

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant