Skip to content

fix mongodb tops module for pymongo v4 compatibility#68662

Open
smartcoder0777 wants to merge 1 commit intosaltstack:masterfrom
smartcoder0777:68659-mongodb-module-not-working-with-pymongo
Open

fix mongodb tops module for pymongo v4 compatibility#68662
smartcoder0777 wants to merge 1 commit intosaltstack:masterfrom
smartcoder0777:68659-mongodb-module-not-working-with-pymongo

Conversation

@smartcoder0777
Copy link

@smartcoder0777 smartcoder0777 commented Jan 27, 2026

Fixes: #68659

What does this PR do?

Fixes the mongodb tops module to work with pymongo v4+ by replacing the deprecated mdb.authenticate() method with authentication credentials passed directly to the MongoClient constructor.

What issues does this PR fix or reference?

Fixes #68659

Previous Behavior

The mongodb tops module used the deprecated mdb.authenticate(user, password) method which was removed in pymongo v4. This caused authentication failures when using pymongo v4.9+ (required for MongoDB v8 compatibility).

conn = pymongo.MongoClient(host=host, port=port, ssl=ssl)
mdb = conn[database]
if user and password:
    mdb.authenticate(user, password)  # ❌ Removed in pymongo v4

New Behavior

Authentication credentials are now passed directly to MongoClient constructor using username, password, and authSource parameters, making it compatible with both pymongo v3 and v4+.

conn_kwargs = {"host": host, "port": port, "ssl": ssl}
if user and password:
    conn_kwargs["username"] = user
    conn_kwargs["password"] = password
    conn_kwargs["authSource"] = authdb  # Defaults to "admin"
conn = pymongo.MongoClient(**conn_kwargs)

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=191128130

@smartcoder0777 smartcoder0777 requested a review from a team as a code owner January 27, 2026 13:06
@smartcoder0777 smartcoder0777 force-pushed the 68659-mongodb-module-not-working-with-pymongo branch from a226342 to 22c2188 Compare January 27, 2026 13:20
@smartcoder0777
Copy link
Author

@bdrx312 Can you review my PR and merge it please?

@twangboy twangboy added the test:full Run the full test suite label Jan 28, 2026
@twangboy twangboy modified the milestones: Approved, Argon v3008.0 Jan 28, 2026
@smartcoder0777
Copy link
Author

@twangboy It looks like the PR passed all checks. Would you merge it and close the issue?
Thanks

@smartcoder0777
Copy link
Author

@dwoz Could you merge my PR and close the issue?
Thanks

@smartcoder0777
Copy link
Author

@twangboy can you merge my PR and close the issue? Thanks

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

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mongodb module not working with pymongo v4

2 participants