Skip to content
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

Merged
merged 3 commits into from
Jun 19, 2019

Conversation

wfscheper
Copy link
Collaborator

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.

@coveralls
Copy link

coveralls commented Mar 19, 2019

Coverage Status

Coverage increased (+0.02%) to 96.117% when pulling 949407a on wfscheper:motor-2.0 into abf294b on Scille:master.

@wfscheper wfscheper changed the title Migrate to motor >=2.0.0 WIP: Migrate to motor >=2.0.0 Mar 21, 2019
@wfscheper wfscheper changed the title WIP: Migrate to motor >=2.0.0 Migrate to motor >=2.0.0 Mar 21, 2019
@lafrech
Copy link
Collaborator

lafrech commented Mar 25, 2019

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

  • use conditions when the code depends on the motor version (most of it would be in the tests)
  • modify setup.py to read ['motor>=1.1,<3.0']
  • modify tox.ini to define motor1 and motor2 instead of just motor
  • modify .travis.yml to test motor1 and motor2 (maybe we can test motor1 on python3.5 and motor2 on python 3.7 rather than all combinations, to limit CI load/time)

Thanks.

@wfscheper
Copy link
Collaborator Author

@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 count(filter, *, with_limit_and_skip=False, **kwargs) that does the version handling for the consumer. What are your thoughts?

@wfscheper wfscheper changed the title Migrate to motor >=2.0.0 Update tests to support motor 2.x Apr 25, 2019
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.
@wfscheper
Copy link
Collaborator Author

wfscheper commented Apr 25, 2019

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.

@lafrech
Copy link
Collaborator

lafrech commented May 6, 2019

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 count_document rather than count. I guess we should do the same here.

This keeps the new umongo api in-line with motor/pymongo.
@wfscheper
Copy link
Collaborator Author

@lafrech, @touilleMan

What needs to be done to get this merged? I'd really like to use the latest supported version of motor with umongo.

@touilleMan
Copy link
Member

@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 we can do is to add you to the maintainers of the project (so with commit/release rights) so you'd be able to handle the support of motor (so motor2, and deciding whether or not supporting motor1 is still useful)

What do you think ? ;-)

@wfscheper
Copy link
Collaborator Author

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.

@lafrech
Copy link
Collaborator

lafrech commented Jun 12, 2019

Great!

Welcome aboard

@touilleMan
Copy link
Member

@wfscheper I've just added you to the project with write rights, welcome aboard ;-)

@wfscheper
Copy link
Collaborator Author

Thanks guys! Looking forward to working on this project with you.

@wfscheper wfscheper changed the title Update tests to support motor 2.x Add count_documents support to motor asyncio Documents Jun 14, 2019
@wfscheper
Copy link
Collaborator Author

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 NotImplementedError: Motor with asyncio prohibits callbacks. I managed to get the callback working and tested for motor 2, but should I raise that same exception instead?

@lafrech
Copy link
Collaborator

lafrech commented Jun 17, 2019

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 if MOTOR_VERSION < (2, 0) condition in to_list to always use the wrapper? Or that you should remove the whole callback wrapper for both cases?

AFAIU, to_list was broken because passing a callback would fail. In this case, adding a wrapper to allow a callback to be passed is a feature, unrelated to the Motor 1 -> 2 change. You can and should do it for both Motor 1 and 2.

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.

@wfscheper
Copy link
Collaborator Author

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.
@lafrech
Copy link
Collaborator

lafrech commented Jun 18, 2019

Makes sense to me. Thanks for investigating.

@wfscheper wfscheper closed this Jun 19, 2019
@wfscheper wfscheper deleted the motor-2.0 branch June 19, 2019 01:39
@wfscheper wfscheper reopened this Jun 19, 2019
@wfscheper wfscheper merged commit bc176b0 into Scille:master Jun 19, 2019
@lafrech
Copy link
Collaborator

lafrech commented Jun 19, 2019

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

@wfscheper
Copy link
Collaborator Author

Will do. I'll add a RELEASING.md; its good to have a checklist.

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