-
Notifications
You must be signed in to change notification settings - Fork 413
Update for PyMongo 4 and add GitHub Actions #845
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
Conversation
|
Converting to draft while I continue to work through the pymongo 4.0 changelog |
stennie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Epic! Thanks for the PR @blink1073 !
| from mtools.util.logfile import LogFile | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function", autouse=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice monkeypatch. Ideally we should be unit testing output of run() rather than grubbing from stdout, but we can fix that later.
|
I went through all of the deprecated functions, and the build is passing, taking this out of draft |
mtools/util/presplit.py
Outdated
| } | ||
| } | ||
| ]) | ||
| print(', '.join(["%s: %i" % (ch['shard'], ch['nChunks']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails because the 'shard' field doesn't exist:
>>> chunk_group = client['config']['chunks'].aggregate([{ '$match': { 'ns': 'test.test2' }},{ '$group': { '_id': '$shard','nChunks': { '$sum': 1 }}}])
>>> list(chunk_group)
[{'_id': 'demo-set-0', 'nChunks': 1}]
>>> chunk_group = client['config']['chunks'].aggregate([{ '$match': { 'ns': 'test.test2' }},{ '$group': { '_id': '$shard','nChunks': { '$sum': 1 }}}])
>>> print(', '.join(["%s: %i" % (ch['shard'], ch['nChunks']) for ch in chunk_group]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
KeyError: 'shard'To fix this we need to add the shard field which is a little awkward in the $group stage. AFAICT you need to use the $first accumulator:
>>> chunk_group = client['config']['chunks'].aggregate([{ '$match': { 'ns': 'test.test2' }},{ '$group': { '_id': '$shard','nChunks': { '$sum': 1 }, 'shard': {'$first': '$shard'}}}])
>>> print(', '.join(["%s: %i" % (ch['shard'], ch['nChunks']) for ch in chunk_group]))
demo-set-0: 1Also this code will not work at all on 5.0 because they removed the "ns" field from the chunks collection. Compare https://docs.mongodb.com/v5.0/reference/config-database/#mongodb-data-config.chunks with https://docs.mongodb.com/v4.4/reference/config-database/#mongodb-data-config.chunks . The config database is internal so can change from release to release. This particular issue should be handled in a new ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, looking at this again there's no need for the 'shard': {'$first': '$shard'}. We're already grouping on the shard field so we can change the list comprehension to use the _id field:
>>> chunk_group = client['config']['chunks'].aggregate([{ '$match': { 'ns': 'test.test2' }},{ '$group': { '_id': '$shard','nChunks': { '$sum': 1 }}}])
>>> print(', '.join(["%s: %i" % (ch['_id'], ch['nChunks']) for ch in chunk_group]))
demo-set-0: 1
ShaneHarvey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pymongo related changes LGTM!
- Adds GitHub Actions testing - Adds Python 3.10 support - Fixes rueckstiess#841 - Adds pymongo 4.0 support - Fixes rueckstiess#844 - Adds handling of `directConnection` - Fixed use of `pymongo.database.Database.authenticate` - Fixed use of `pymongo.database.Database.add_user` - Fixed use of `pymongo.collection.Collection.insert` - Fixed use of `pymongo.collection.Collection.update` - Fixed use of `pymongo.collection.Collection.ensure_index` - Fixed use of `pymongo.collection.Collection.count` - Fixed use of `pymongo.collection.Collection.group` - Adds `pytest` support (needed for GitHub Actions support) - Fixes rueckstiess#842
- Adds GitHub Actions testing - Adds Python 3.10 support - Fixes rueckstiess#841 - Adds pymongo 4.0 support - Fixes rueckstiess#844 - Adds handling of `directConnection` - Fixed use of `pymongo.database.Database.authenticate` - Fixed use of `pymongo.database.Database.add_user` - Fixed use of `pymongo.collection.Collection.insert` - Fixed use of `pymongo.collection.Collection.update` - Fixed use of `pymongo.collection.Collection.ensure_index` - Fixed use of `pymongo.collection.Collection.count` - Fixed use of `pymongo.collection.Collection.group` - Adds `pytest` support (needed for GitHub Actions support) - Fixes rueckstiess#842
Description of changes
directConnectionpymongo.database.Database.authenticatepymongo.database.Database.add_userpymongo.collection.Collection.insertpymongo.collection.Collection.updatepymongo.collection.Collection.ensure_indexpymongo.collection.Collection.countpymongo.collection.Collection.grouppytestsupport (needed for GitHub Actions support) - Fixes Replace Nose with an actively maintained unit testing library #842Testing
toxon macOSO/S testing: