-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add count_documents support to motor asyncio Documents #184
Conversation
I'm not familiar with motor and the async part of umongo, but I gave it a look and it looks like it would be easy to support both motor 1.x and motor 2.x with the same umongo codebase. Dropping currently supported versions of motor would be a breaking change, but supporting new versions while keeping support for older ones would just be a minor change. We can drop motor 1.x in a later major version. Do you think you could change your PR to keep compatibility with old motor versions? Basically, that means
Thanks. |
@lafrech, you're correct about it being easy to support both versions of motor, so I'm updating my pull request. I can see two ways to address this. One is that I don't change the public API of umongo and just make the changes you suggested. The other way is to add a new Document classmethod |
Motor 2.0 deprecated the cursor.count() method in favor of Collection.count_documents. This adds a count() class method to the motor asyncio Document class that handles the two different ways to count documents based on the version of motor.
Updated this branch to fix the tests. I also pushed a count-method branch that adds a new method to abstract the different ways of counting documents in motor. |
I'm sorry, @wfscheper, I don't have time for this and I don't use motor. Maybe @touilleMan will be able to check and merge this PR. I worked on something similar for the pymongo driver (#149) and we chose to stick to the pymongo API by naming the method |
This keeps the new umongo api in-line with motor/pymongo.
What needs to be done to get this merged? I'd really like to use the latest supported version of motor with umongo. |
@wfscheper I no longer have time to support this project and @lafrech is not a motor user so it seems pretty hard for us to merge this PR What do you think ? ;-) |
I'm willing to take on maintaining the motor support for umongo. I have two projects at work that are using umongo + motor, so I'll definitely have the motivation. I will go ahead and update this PR with the changes I made to the count-method branch (renaming the method to count_documents per @lafrech's comment. |
@wfscheper I've just added you to the project with write rights, welcome aboard ;-) |
Thanks guys! Looking forward to working on this project with you. |
So while trying to get test coverage over the code I added to WrappedCursor.to_list, I discovered that in motor 1.x passing a callback to to_list raises |
I'm not sure I understand the point. Does this mean that Motor 1 and 2 behave the same about callbacks and you could remove the AFAIU, Maybe for clarity, you could do the Motor 1&2 compatibility change in one move, then add the wrapper (for bother Motor versions) in another move if needed. Just guessing. I have no idea what I'm talking about. As written above I don't use and don't know async frameworks. |
So the bottom line is that Motor never supported using callbacks with to_list() when using the asyncio version of the driver. If I were more familiar with motor prior to 2.x, I probably would've known that ahead of time. I feel that it's a bad idea to add support for callbacks to WrappedCursor.to_list when the underlying driver never supported them, as it would cause umongo+motor to behave differently than how motor is documented. I'm leaning towards removing the callback wrapper entirely and letting motor 1.x throw NotImplementedError and 2.x throw TypeError for the call signature. Seems the best mix of backwards compatibility in umongo and behavioral compatibility with the driver. |
Motor never supported passing callbacks to to_list when using asyncio, so we aren't actually gaining any compatibility by trying to enable it here. Instead, adjust how we call to_list() to only use the callback keyword argument if a callback was passed in. This will cause motor to throw the appropriate Exception based on which version is installed.
Makes sense to me. Thanks for investigating. |
Great. So this is a non-breaking change and it can be released as a minor version, right? I just updated AUTHORS.rst. @wfscheper, would you like to update CHANGELOG and release? Release process: #84 (comment) or #101 (comment). (We could add a RELEASE doc like in marshmallow: https://github.com/marshmallow-code/marshmallow/blob/dev/RELEASING.md.) |
Will do. I'll add a RELEASING.md; its good to have a checklist. |
Update API to support v2.0.0 of motor. This involves changing tests
that use the deprecated count() cursor method to use either
count_documents() or to_list() instead, and removing the callback
keyword argument from the to_list wrapper.