Skip to content

feat(fiftyone-odm): TEAMS-4199 automated fcv handling #5639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 28, 2025

Conversation

afoley587
Copy link
Member

@afoley587 afoley587 commented Mar 24, 2025

What changes are proposed in this pull request?

Various versions of mongoDB are being deprecated and moving to EOL. FiftyOne should be able to be updated with those changes. MongoDB has a few version numbers and, of importance, are the server version and the feature compatibility version (FCV). The server version is the version of the binary that is running while the FCV tells the database which server features to be compatible with.

With embedded databases (ones spawned by FO), we should check this FCV and, if required, increase it to the same major version as the server. For reference, see the mongodb docs.

Originally, this was the following 2 PRs:

How is this patch tested? If it is not, please explain why.

Case 1 - If database_validation=False OR database_admin=False

Background

If database_validation=False OR database_admin=False:

  • MIN_MONGODB_VERSION is not enforced
  • No log messages due to FCV are generated

Test

$ export FIFTYONE_DATABASE_VALIDATION=false
$ python
Python 3.10.16 (main, Feb  7 2025, 18:42:07) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
>>> fo.list_datasets()
[]
>>> 
Case 2a.1 - Using the internal/embedded mongo instance

Background

If database_admin=True AND database_validation=True

  • Always raise an exception when $curr_mongodb_version < MIN_MONGODB_VERSION
  • If _db_service != None, Automatically issue admin command to upgrade FCV
    according to MongoDB best practices

In this test, we will validate that this occurs IFF both settings are true and
_db_service is not None.

Test

First, install/run fiftyone from PyPi

$ pip install fiftyone
$ $HOME/.venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod --version
db version v6.0.5
Build Info: {
    "version": "6.0.5",
    "gitVersion": "c9a99c120371d4d4c52cbb15dac34a36ce8d3b1d",
    "openSSLVersion": "OpenSSL 3.0.15 3 Sep 2024",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2204",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Now, run FO:

>>> import fiftyone as fo
>>> import fiftyone.zoo as foz
>>> dataset = foz.load_zoo_dataset("coco-2017-validation-50")
>>> session = fo.launch_app(dataset)
>>> dataset.persistent = True
>>> exit()

Then, build from source which should trigger update

$ git clone https://github.com/voxel51/fiftyone.git \
    -b afoley/teams-4199-automated-fcv-handling
$ cd fiftyone
$ bash install.bash -d
$ export PYTHONPATH=$PWD:$PYTHONPATH
# Force update the mongo binary so server version > fc version
$ wget -O mongo-next.tgz \
    https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian12-7.0.18.tgz
$ tar xvzf mongo-next.tgz
$ find mongodb-linux-* \
    -name mongod -exec cp {} \
    $HOME/.venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod \;
$ $HOME/.venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod --version
db version v7.0.18
Build Info: {
    "version": "7.0.18",
    "gitVersion": "1624e181d0dac03edb34ef25b9b58a6d79969825",
    "openSSLVersion": "OpenSSL 3.0.15 3 Sep 2024",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "debian12",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Now, run FO:

>>> import fiftyone as fo
>>> fo.config.database_admin
True
>>> fo.config.database_validation
True
>>> fo.list_datasets()
Your MongoDB server version is newer than your feature compatibility version. Upgrading the feature compatibility version now. You can suppress this exception by setting your `database_validation` config parameter to `False`. See https://docs.voxel51.com/user_guide/config.html#configuring-a-mongodb-connection for more information
['coco-2017-validation-50']

$ mongosh localhost:33707 -eval "db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })"
{ featureCompatibilityVersion: { version: '7.0' }, ok: 1 }
Case 2a.2 - Using the internal/embedded mongo instance

Background

If database_admin=True AND database_validation=True

  • Always raise an exception when $curr_mongodb_version < MIN_MONGODB_VERSION
  • If _db_service != None, Automatically issue admin command to upgrade FCV
    according to MongoDB best practices

In this test, We will perform another forced mongo update.
In this case, we will set fiftyone db admin to false and make sure the parameters are respected.

Test

First, force upgrade mongo:

$ rm -rf mongo-next.tgz mongodb-linux-x86_64-debian12-7.0.18
$ wget -O mongo-next.tgz \
    https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian12-8.0.6.tgz
$ tar xvzf mongo-next.tgz
$ find mongodb-linux-* \
    -name mongod -exec cp {} \
    $HOME/.venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod \;
$ $HOME/.venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod --version
db version v8.0.6
Build Info: {
    "version": "8.0.6",
    "gitVersion": "80f21521ad4a3dfd5613f5d649d7058c6d46277f",
    "openSSLVersion": "OpenSSL 3.0.15 3 Sep 2024",
    "modules": [],
    "allocator": "tcmalloc-google",
    "environment": {
        "distmod": "debian12",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

And then run FO. Note the lack of log messages:

$ export FIFTYONE_DATABASE_ADMIN=false
$ python
Python 3.10.16 (main, Feb  7 2025, 18:42:07) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
>>> fo.config.database_admin
False
>>> fo.config.database_validation
True
>>> fo.list_datasets()
['coco-2017-validation-50']
>>> exit()

Now, set the configuration to true and observe the upgrade:

$ export FIFTYONE_DATABASE_ADMIN=true
$ python
Python 3.10.16 (main, Feb  7 2025, 18:42:07) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
>>> fo.config.database_admin
True
>>> fo.config.database_validation
True
>>> fo.list_datasets()
Your MongoDB server version is newer than your feature compatibility version. Upgrading the feature compatibility version now. You can suppress this exception by setting your `database_validation` config parameter to `False`. See https://docs.voxel51.com/user_guide/config.html#configuring-a-mongodb-connection for more information
['coco-2017-validation-50']

Validating the FCV:

$ mongosh localhost:41287 -eval "db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })"
{ featureCompatibilityVersion: { version: '8.0' }, ok: 1 }
$ 
Case 2b - Respecting External Databases

Background

If database_admin=True AND database_validation=True

  • Always raise an exception when $curr_mongodb_version < MIN_MONGODB_VERSION
  • If _db_service != None, Automatically issue admin command to upgrade FCV
    according to MongoDB best practices

In this test, we will validate that FO will not manage any FCV is
this is an external database (_db_service is None).

Test

In one shell, run an external mongo:

$ docker run -it --rm -p 27018:27017 -v ./db:/data/db mongo:4.4
# Run it again so FCV != server
$ docker run -it --rm -p 27018:27017 -v ./db:/data/db mongo:5.0

And connect to it. In this case, the logs should be shown but no actions performed (FCV is STILL on 4.4):

$ export FIFTYONE_DATABASE_URI=mongodb://localhost:27018
$ python
Python 3.10.16 (main, Feb  7 2025, 18:42:07) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
>>> fo.config.database_admin
True
>>> fo.config.database_validation
True
>>> fo.list_datasets()
You are running the oldest supported major version of mongodb. Please refer to https://deprecation.voxel51.com for deprecation notices. You can suppress this exception by setting your `database_validation` config parameter to `False`. See https://docs.voxel51.com/user_guide/config.html#configuring-a-mongodb-connection for more information
[]
>>> 

Verifying that mongo wasn't upgraded:

$ mongosh "localhost:27018" \
    -eval "db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })"
{ featureCompatibilityVersion: { version: '4.4' }, ok: 1 }

Now, disable database validation and observe that there are no logs:

$ export FIFTYONE_DATABASE_VALIDATION=false
$ python
Python 3.10.16 (main, Feb  7 2025, 18:42:07) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
>>> fo.list_datasets()
[]
>>> 

See below for "how were the docs tested"

Screenshot 2025-03-25 at 9 54 37 AM

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

FiftyOne will now manage the feature compatibility version (FCV) of the FiftyOne-managed mongodb instance. This management will happen during the first connection to the database. Customers who utilize an external/standalone instance will be unaffected.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

Summary by CodeRabbit

  • Documentation

    • Updated the installation guide to specify the required Python version as 3.9 - 3.12.
    • Added a note regarding automatic management of MongoDB feature compatibility version starting from FiftyOne version 1.5.0.
    • Clarified options for using the default automatic database configuration or setting up a custom MongoDB connection.
  • New Features

    • Enhanced the database connection logic to automatically manage MongoDB feature compatibility version during upgrades.
  • Tests

    • Added comprehensive tests to validate the MongoDB feature compatibility version update process, covering various scenarios and error handling.

@afoley587 afoley587 requested a review from brimoor March 24, 2025 20:52
Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

Walkthrough

This pull request introduces updates to the installation documentation for FiftyOne, reflecting a change in the required Python version to 3.9 - 3.12 and adding a note about automatic management of MongoDB feature compatibility versions starting from FiftyOne version 1.5.0. Additionally, two new constants related to MongoDB compatibility are defined, and several new functions for managing the feature compatibility version (FCV) are implemented in the database module. A new test suite is also added to validate the FCV update logic.

Changes

Files Change Summary
docs/.../install.rst Updated Python version requirement to 3.9 - 3.12; added note on automatic MongoDB FCV management and modified existing note for clarity.
fiftyone/constants.py Renamed constant: MIN_MONGODB_VERSION to MONGODB_MIN_VERSION; added constants: MONGODB_MAX_ALLOWABLE_FCV_DELTA = 1 and MONGODB_SERVER_FCV_REQUIRED_CONFIRMATION = Version("7.0").
fiftyone/core/odm/database.py Added functions for FCV management: _get_fcv_and_version, _is_fcv_upgradeable, and _update_fc_version; modified establish_db_conn to include FCV updates.
tests/unittests/fcv_tests.py Introduced TestUpdateFCV class to validate the _update_fc_version function with various scenarios and error handling.

Possibly related PRs

Suggested labels

enhancement, documentation

Suggested reviewers

  • findtopher
  • benjaminpkane
  • afoley587

Poem

Oh, I’m a rabbit hopping along,
Coding through docs with a joyful song.
FCV updates are now in sight,
Constants and tests make it all so right.
With whiskers twitching in pure delight,
I celebrate these changes day and night!
🐇🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@findtopher findtopher left a comment

Choose a reason for hiding this comment

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

I liked it the first time, I like it this time!

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (4)
docs/source/getting_started/install.rst (1)

217-225: Correct minor typos in documentation note
Fix the spelling of "conection" → "connection" and "FiftyOnes" → "FiftyOne's".

Apply this diff to correct the typos:

-  :ref:`MongoDB conection <configuring-mongodb-connection>`
-  outside of FiftyOnes administrative management.
+  :ref:`MongoDB connection <configuring-mongodb-connection>`
+  outside of FiftyOne's administrative management.
tests/unittests/fcv_tests.py (3)

15-25: Consider refining docstring or method naming
_get_expected_update_call cleanly builds the expected MongoDB command. You may want to make it public if it is reused or rename it to indicate it’s for testing FCV commands if that clarifies usage.


26-87: test_update_fcv_success—well-structured functional test

  1. The subTest usage is beneficial for clarity.
  2. Nested with statements at lines 48-51 could be combined per static analysis for cleaner code.
-with patch("pymongo.MongoClient") as mock_client:
-    with patch("fiftyone.core.odm.database._get_logger") as mock_get_logger:
+with patch("pymongo.MongoClient") as mock_client, \
+     patch("fiftyone.core.odm.database._get_logger") as mock_get_logger:
🧰 Tools
🪛 Ruff (0.8.2)

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-51: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


45-45: Remove unused mock_db_service assignments
Ruff flagged these lines where mock_db_service is assigned but never used.

-        mock_db_service = {}

(Apply this removal for each of the flagged lines shown above.)

Also applies to: 98-98, 153-153, 208-208, 262-262, 282-282, 321-321, 362-362, 401-401, 439-439, 477-477

🧰 Tools
🪛 Ruff (0.8.2)

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4e7332 and b0ba184.

📒 Files selected for processing (4)
  • docs/source/getting_started/install.rst (1 hunks)
  • fiftyone/constants.py (1 hunks)
  • fiftyone/core/odm/database.py (4 hunks)
  • tests/unittests/fcv_tests.py (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
tests/unittests/fcv_tests.py (1)
fiftyone/core/odm/database.py (1)
  • _update_fc_version (1753-1817)
🪛 Ruff (0.8.2)
tests/unittests/fcv_tests.py

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-51: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build
🔇 Additional comments (15)
fiftyone/constants.py (1)

105-106: Constants appear correct and well-named
No issues with these constants, and they cleanly convey their meaning.

tests/unittests/fcv_tests.py (11)

1-14: Imports and initial setup look good
No issues noted in these import statements, and the unittest.mock usage is appropriate.


88-140: test_update_fcv_success_minor_and_patch_versions—test coverage looks good
This test effectively verifies FCV updates when MongoDB versions differ by minor or patch increments. Implementation is logically consistent.

🧰 Tools
🪛 Ruff (0.8.2)

98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


142-196: test_update_fcv_success_fcv_less_than_min_version—robust boundary check
Covers an edge case of server version meeting the minimum while FCV is below it. Nicely done.

🧰 Tools
🪛 Ruff (0.8.2)

153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


198-247: test_update_fcv_log_minimum_version—good use of assertion checks
Ensures no unintended upgrade call for identical oldest supported version. Helpful for preventing regressions.

🧰 Tools
🪛 Ruff (0.8.2)

208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


255-271: test_connection_error—connection error scenario
Raising a ConnectionError ensures consistent error handling across validation calls. Looks correct.

🧰 Tools
🪛 Ruff (0.8.2)

262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


273-311: test_version_diff_warning—validates large version gap
Properly triggers a warning for major version differences beyond the allowed delta. Implementation aligns with design.

🧰 Tools
🪛 Ruff (0.8.2)

282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


313-351: test_fcv_greater_than_server_version_warning—thorough coverage
Checks for FCV outpacing the server version. The test logic sufficiently covers and logs this mismatch scenario.

🧰 Tools
🪛 Ruff (0.8.2)

321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


353-391: test_oldest_supported_version_warning—ensures no unwanted upgrade
This test enforces that only logs occur when both FCV and server version are at the lowest support level. Good negative test.

🧰 Tools
🪛 Ruff (0.8.2)

362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


393-429: test_update_fc_version_operation_failure—valid OperationFailure coverage
Confirms that errors are logged and no unhandled exceptions propagate. Correct approach for robust error handling.

🧰 Tools
🪛 Ruff (0.8.2)

401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


431-467: test_update_fc_version_pymongo_failure—verifying PyMongoError
Similar coverage for a different exception type. Good for ensuring broad reliability.

🧰 Tools
🪛 Ruff (0.8.2)

439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


469-523: test_no_action_unless_managed—prevents upgrades when _db_service is None
Successfully tests scenario in which FiftyOne does not manage the database. Implementation is consistent.

🧰 Tools
🪛 Ruff (0.8.2)

477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

fiftyone/core/odm/database.py (3)

1653-1681: _get_fcv_and_version—solid retrieval of FCV and server version

  1. Properly raises ConnectionError on ServerSelectionTimeoutError.
  2. Implementation is concise and clear.

1683-1751: _is_fcv_upgradeable—comprehensive checks
Handles multiple mismatch scenarios carefully (FCV > server, large version gaps, and oldest supported version). Logs are explicit.


1753-1817: _update_fc_version—key logic to upgrade FCV
Implementation covers warnings, errors, and major version check thoroughly. Reliance on _db_service is consistent with the design.

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (12)
tests/unittests/fcv_tests.py (12)

45-45: Fix unused variable assignment.

The mock_db_service variable is assigned but never used. The patched _db_service is already handled by the decorator.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-53: Simplify nested context managers.

Multiple nested with statements can be combined for improved readability.

-            with self.subTest(
-                server_version=server_version, fc_version=fc_version
-            ):
-                with patch("pymongo.MongoClient") as mock_client, patch(
-                    "fiftyone.core.odm.database._get_logger"
-                ) as mock_get_logger:
+            with self.subTest(
+                server_version=server_version, fc_version=fc_version
+            ), patch("pymongo.MongoClient") as mock_client, patch(
+                "fiftyone.core.odm.database._get_logger"
+            ) as mock_get_logger:
🧰 Tools
🪛 Ruff (0.8.2)

48-53: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


98-98: Fix unused variable assignment.

Similar to earlier instances, the mock_db_service variable is assigned but never used.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


153-153: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


208-208: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


262-262: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


282-282: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


321-321: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


362-362: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


401-401: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


439-439: Fix unused variable assignment.

Same issue with unused mock_db_service variable.

-        mock_db_service = {}
+        # Database service should exist for this test
🧰 Tools
🪛 Ruff (0.8.2)

439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


1-523: Overall test suite is comprehensive and robust.

The test suite is well-structured and covers a wide range of scenarios for the FCV update functionality, including success cases, edge cases, and various error conditions. The mocking approach effectively isolates the tests from actual MongoDB dependencies.

Consider adding assertions for specific functions being called (like server_info()) rather than just focusing on the final command calls. This would provide even more validation of the expected code paths.

🧰 Tools
🪛 Ruff (0.8.2)

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-53: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0ba184 and 32e9e8c.

📒 Files selected for processing (2)
  • docs/source/getting_started/install.rst (1 hunks)
  • tests/unittests/fcv_tests.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/source/getting_started/install.rst
🧰 Additional context used
🧬 Code Definitions (1)
tests/unittests/fcv_tests.py (1)
fiftyone/core/odm/database.py (1)
  • _update_fc_version (1753-1817)
🪛 Ruff (0.8.2)
tests/unittests/fcv_tests.py

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-53: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: modified-files
  • GitHub Check: build
🔇 Additional comments (14)
tests/unittests/fcv_tests.py (14)

1-13: Imports look good!

The imports are appropriate for a test file, including unittest, mock utilities, pymongo error types, and the function under test.


15-24: Helper method is well implemented.

The _get_expected_update_call helper method cleanly abstracts the construction of the MongoDB command, handling the conditional addition of the confirm flag based on version requirements.


26-87: Test cases thoroughly verify successful FCV updates.

The test comprehensively verifies the FCV update functionality across multiple version increments, ensuring proper command execution and logging.

🧰 Tools
🪛 Ruff (0.8.2)

45-45: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


48-53: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


88-140: Test case correctly verifies minor and patch version handling.

This test ensures that MongoDB's minor and patch version differences are properly handled during FCV updates, including verifying appropriate warning messages.

🧰 Tools
🪛 Ruff (0.8.2)

98-98: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


142-195: Test case effectively handles edge case with FCV below minimum version.

The test properly verifies the behavior when the FCV is below the minimum supported version while the server version is at the minimum. This is a good edge case to cover.

🧰 Tools
🪛 Ruff (0.8.2)

153-153: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


197-254: Good test for minimum version edge case.

Excellent test case that verifies when both versions are at minimum support level, no action is taken beyond logging warnings.

🧰 Tools
🪛 Ruff (0.8.2)

208-208: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


255-271: Connection error handling test is well implemented.

The test correctly verifies that connection errors are properly propagated as ConnectionError exceptions.

🧰 Tools
🪛 Ruff (0.8.2)

262-262: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


272-311: Version difference warning test is well implemented.

The test properly verifies that warnings are logged when the MongoDB server version is significantly ahead of the FCV.

🧰 Tools
🪛 Ruff (0.8.2)

282-282: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


312-350: Test case for FCV greater than server version is thorough.

Good validation of warning behavior when FCV exceeds server version, which is an important edge case to handle.

🧰 Tools
🪛 Ruff (0.8.2)

321-321: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


351-391: Great test for minimum supported version warning.

The test effectively verifies that appropriate warnings are generated when running the oldest supported MongoDB version.

🧰 Tools
🪛 Ruff (0.8.2)

362-362: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


392-428: Operation failure test is well implemented.

The test properly verifies error logging when the FCV update operation fails, including checking for the correct error message.

🧰 Tools
🪛 Ruff (0.8.2)

401-401: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


430-466: PyMongo failure test is well implemented.

The test effectively verifies error logging behavior for general PyMongo errors during FCV updates.

🧰 Tools
🪛 Ruff (0.8.2)

439-439: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


468-523: Test for unmanaged instances is well implemented.

This test properly verifies that only logging occurs (no actual updates) when the database instance is not managed by FiftyOne.

🧰 Tools
🪛 Ruff (0.8.2)

477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)


477-477:

✅ Verification successful

Intentional assignment of None to mock_db_service.

This is the only test where assigning to mock_db_service is intentional and correct, as it tests the behavior when the service is None. However, ensure this assignment actually affects the patched value.


🏁 Script executed:

#!/bin/bash
# Verifying how patched variables work with assignments

# Let's check if there are any similar patterns in the codebase
rg -A 2 -B 2 "mock_\w+ = None" --glob "tests/**/*.py"

Length of output: 388


Review Verification: Confirmed Intentional Assignment of None in fcv_tests.py

The search confirms that the assignment of None to mock_db_service in tests/unittests/fcv_tests.py is unique to this test and matches the intended behavior. Please ensure that this assignment correctly propagates to the patched mechanism in your test setup.

🧰 Tools
🪛 Ruff (0.8.2)

477-477: Local variable mock_db_service is assigned to but never used

Remove assignment to unused variable mock_db_service

(F841)

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
fiftyone/core/odm/database.py (2)

1683-1750: Comprehensive FCV upgrade eligibility checks.

The function thoroughly handles all edge cases with appropriate warning messages. It correctly prevents upgrades in potentially problematic scenarios.

Consider adding a return type annotation for consistency with other functions:

-def _is_fcv_upgradeable(fc_version: Version, server_version: Version) -> bool:
+def _is_fcv_upgradeable(fc_version: Version, server_version: Version) -> bool:

1753-1817: Solid implementation of FCV update mechanism.

The function correctly handles the MongoDB server version-specific requirements (like the confirm flag for 7.0+) and provides informative error messages if the update fails.

Consider adding a return type annotation for consistency:

-def _update_fc_version(client: pymongo.MongoClient):
+def _update_fc_version(client: pymongo.MongoClient) -> None:
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92ece75 and 0f74963.

📒 Files selected for processing (2)
  • docs/source/getting_started/install.rst (3 hunks)
  • fiftyone/core/odm/database.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/source/getting_started/install.rst
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.12)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build
🔇 Additional comments (3)
fiftyone/core/odm/database.py (3)

15-15: Proper imports added for new functionality.

The addition of the Tuple type and specific MongoDB error classes is necessary for the new feature compatibility version (FCV) handling functions.

Also applies to: 25-31


235-236: Well-integrated FCV update mechanism.

The code properly conditionally calls the new FCV update mechanism only when both database validation and admin permissions are enabled, ensuring it won't affect users connecting to external databases.


1653-1680: Well-implemented FCV and version retrieval function.

Good type annotations, error handling, and clear docstring. The function properly fetches both the feature compatibility version and server version, converting them to Version objects for comparison.

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

Thank you sir! 🫡

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/unittests/fcv_tests.py (1)

303-307: Minor spelling fix.

In the docstring referencing “feature compatability,” please correct “compatability” to “compatibility.”

-    """Tests the warning that's generated in the event that
-    the feature compatability version is ahead of the server version.
+    """Tests the warning that's generated in the event that
+    the feature compatibility version is ahead of the server version.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f74963 and 2e0a29b.

📒 Files selected for processing (3)
  • fiftyone/constants.py (1 hunks)
  • fiftyone/core/odm/database.py (5 hunks)
  • tests/unittests/fcv_tests.py (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
tests/unittests/fcv_tests.py (1)
fiftyone/core/odm/database.py (1)
  • _update_fc_version (1753-1817)
fiftyone/core/odm/database.py (1)
fiftyone/core/dataset.py (1)
  • version (687-691)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.12)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: build / build
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: e2e / test-e2e
  • GitHub Check: lint / eslint
  • GitHub Check: build
🔇 Additional comments (7)
fiftyone/constants.py (1)

104-106: All constants appear well-defined and aligned with the intended usage.

tests/unittests/fcv_tests.py (1)

1-503: Comprehensive test coverage.

These tests thoroughly validate FCV upgrade scenarios, error handling, and logging behavior. Great use of mocks to cover various MongoDB states.

fiftyone/core/odm/database.py (5)

8-8: No functional changes detected.


15-15: Correct import for typed return values.


25-31: Consolidated imports for error handling.


235-236: Conditional FCV update is coherent.

This ensures that FCV change logic only runs when both admin privileges and database validation are enabled.


1653-1818: Robust FCV management logic.

These new helper functions cleanly handle FCV detection, upgrade checks, and controlled error handling. The flow is well-structured and thoroughly tested.

Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

🇲🇳

@afoley587 afoley587 merged commit 586fffe into develop Mar 28, 2025
15 checks passed
@afoley587 afoley587 deleted the afoley/teams-4199-automated-fcv-handling branch March 28, 2025 15:28
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.

4 participants