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

Modifications to enable pymongo 3.0.x compatability. #63

Merged
merged 1 commit into from
Oct 19, 2015
Merged

Modifications to enable pymongo 3.0.x compatability. #63

merged 1 commit into from
Oct 19, 2015

Conversation

hbldh
Copy link
Contributor

@hbldh 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
Copy link
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
Copy link

👍

@hbldh
Copy link
Contributor Author

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
Copy link
Contributor

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

I'm all for this being merged as is then

@jbouzekri
Copy link
Contributor

+1

2 similar comments
@phaethon
Copy link

+1

@drankinn
Copy link

+1

@ranman
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link

Big +1 on this. Is this still mergeable?

* 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.
@lucidfrontier45
Copy link

+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 added a commit that referenced this pull request Oct 19, 2015
Modifications to enable pymongo 3.0.x compatability.
@ranman ranman merged commit a21fda7 into mongodb-labs:master Oct 19, 2015
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.

9 participants