-
Notifications
You must be signed in to change notification settings - Fork 404
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
Update for PyMongo 4 and add GitHub Actions #845
Conversation
Converting to draft while I continue to work through the pymongo 4.0 changelog |
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 !
import mtools | ||
from mtools.mloginfo.mloginfo import MLogInfoTool | ||
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
'nChunks': { '$sum': 1 } | ||
} | ||
} | ||
]) | ||
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: 1
Also 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
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!
Description of changes
directConnection
pymongo.database.Database.authenticate
pymongo.database.Database.add_user
pymongo.collection.Collection.insert
pymongo.collection.Collection.update
pymongo.collection.Collection.ensure_index
pymongo.collection.Collection.count
pymongo.collection.Collection.group
pytest
support (needed for GitHub Actions support) - Fixes Replace Nose with an actively maintained unit testing library #842Testing
tox
on macOSO/S testing: