Modifications to enable pymongo 3.0.x compatability. #63

Merged
merged 1 commit into from Oct 19, 2015

Projects

None yet

9 participants

@hbldh
Contributor
hbldh commented Jul 2, 2015

This pull request is an attempt of enabling the use of pymongo >= 3.0.

In __init__.py and the test files there are explicit tests whether pymongo >= 3.0 is used, which is ugly, but I have deemed it necessary to bridge the deprecation problems.

Modifications:

  • Removed auto_start_request from init in the pymongo >= 3.0 case.
  • Using only the MongoClient for pymongo >= 3.0 case, since MongoReplicaSetClient is labelled deprecated and all functionality has been merged to MongoClient.
  • Wrappers has a overriding __getitem__ method added. In pymongo < 3.0 the __getitem__ method (used when calling c[db_name]) called the __getattr__ method (used when calling c.db_name), so wrappers did not need to override both then. In pymongo > 3.0 this is not the case and both have to be overridden.
  • Tests in test_config.py use mongo.cx.address property instead of host and port properties of the MongoClient in the pymongo >= 3.0 case, since they have been removed. All tests using this property also sleeps a short time since the client needs some time to establish connection to MongoDB and set the proper values, otherwise the tests fails.
  • The safe keyword is deprecated for insert and update methods, though only flagged in pymongo 2.x. Change all these to w=1 which has equal effect. insert method also has a deprecation warning in pymongo 3.0.x, so insert_one is used instead in these cases.
@markunsworth
Contributor

Nice one.

Removing the MongoReplicaSetClient would mean this is not backwards compatible with pymongo 2.x - is this desirable?

This was referenced Jul 14, 2015
@nicolaiarocci

👍

@hbldh
Contributor
hbldh commented Jul 14, 2015

@markunsworth The MongoReplicaSetClient is not removed in the pymongo < 3.0 case. It is still the preferred way of connecting to a Replica Set in that case and should definitely be used.

Check __init__.py, lines 232 to 240 to see that an explicit check is done for pymongo < 3.x and then, if found True, using the pre-existing code for selecting the connection class.

@markunsworth
Contributor

Sorry I didn't actually read the commit message properly.

I'm all for this being merged as is then

@jbouzekri

+1

@phaethon

+1

@drankinn

+1

@ranman
Collaborator
ranman commented Aug 7, 2015

Hey this looks good and I'm all set to merge it after some more testing. Mind giving it one more once over to make sure there's nothing you want to change since it's been a while.

@hbldh
Contributor
hbldh commented Aug 7, 2015

@ranman Did as you suggested, gave it a once over and saw some minor mistakes I made, mainly PEP8 violations. Sadly the Travis build for Python 3.4 failed and it seems to be due to that the MongoClient took longer time than 0.01 seconds to establish connection to the database and set its address properties. It should work, either by just running it again or increasing the sleep duration. Neither suggestion is especially compelling...

@ColeKettler

Big +1 on this. Is this still mergeable?

@hbldh hbldh Modifications to enable pymongo 3.0.x compatability.
* Removed `auto_start_request` from __init__ in the pymongo >= 3.0 case.

* Using only the MongoClient for pymongo >= 3.0 case, since
  MongoReplicaSetClient is labelled deprecated and all functionality
  has been merged to MongoClient.

* Wrappers has a overriding `__getitem__` method added. In pymongo < 3.0 the
  `__getitem__` method (used when calling c[db_name]) called the `__getattr__`
  method (used when calling c.db_name), so wrappers did not need to override both then.
  In pymongo > 3.0 this is not the case.

* Tests in test_config.py use `mongo.cx.address` property instead of
  `host` and `port` properties of the MongoClient in the pymongo >= 3.0 case,
  since they have been removed. All tests using this property also
  sleeps a short time since the client needs some time to establish
  connection to MongoDB and set the proper values, otherwise the tests fails.

* The `safe` keyword is deprecated for insert method, though only flagged
  in pymongo 2.x. Change all these to `w=1` which has equal effect.
  `insert` method also has a deprecation warning in pymongo 3.0.x,
  so `insert_one` is used instead in these cases.
0d58b2e
@lucidfrontier45

+1

I think 3.0 compatibility is very important feature and I'm waiting for this PR to be merged.
What is current status?

@ranman ranman merged commit a21fda7 into dcrosta:master Oct 19, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment