Skip to content

PYTHON-1321 Remove MongoReplicaSetClient #552

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

Merged
merged 3 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions doc/api/pymongo/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

Alias for :class:`pymongo.mongo_client.MongoClient`.

.. data:: MongoReplicaSetClient

Alias for :class:`pymongo.mongo_replica_set_client.MongoReplicaSetClient`.

.. data:: ReadPreference

Alias for :class:`pymongo.read_preferences.ReadPreference`.
Expand Down Expand Up @@ -46,7 +42,6 @@ Sub-modules:
errors
message
mongo_client
mongo_replica_set_client
monitoring
operations
pool
Expand Down
32 changes: 0 additions & 32 deletions doc/api/pymongo/mongo_replica_set_client.rst

This file was deleted.

1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Breaking Changes in 4.0
- Removed :meth:`pymongo.database.Database.collection_names`.
- Removed :meth:`pymongo.collection.Collection.parallel_scan`.
- Removed :mod:`pymongo.thread_util`.
- Removed :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient`.

Notable improvements
....................
Expand Down
9 changes: 9 additions & 0 deletions doc/migrate-to-pymongo4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Warnings can also be changed to errors::
.. note:: Not all deprecated features raise :exc:`DeprecationWarning` when
used. See `Removed features with no migration path`_.

MongoReplicaSetClient
---------------------

Removed :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient`.
Since PyMongo 3.0, ``MongoReplicaSetClient`` has been identical to
:class:`pymongo.mongo_client.MongoClient`. Applications can simply replace
``MongoReplicaSetClient`` with :class:`pymongo.mongo_client.MongoClient` and
get the same behavior.

MongoClient
-----------

Expand Down
1 change: 0 additions & 1 deletion pymongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def get_version_string():
MAX_SUPPORTED_WIRE_VERSION)
from pymongo.cursor import CursorType
from pymongo.mongo_client import MongoClient
from pymongo.mongo_replica_set_client import MongoReplicaSetClient
from pymongo.operations import (IndexModel,
InsertOne,
DeleteOne,
Expand Down
2 changes: 1 addition & 1 deletion pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def validate_read_preference(dummy, value):


def validate_read_preference_mode(dummy, value):
"""Validate read preference mode for a MongoReplicaSetClient.
"""Validate read preference mode for a MongoClient.

.. versionchanged:: 3.5
Returns the original ``value`` instead of the validated read preference
Expand Down
6 changes: 2 additions & 4 deletions pymongo/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,7 @@ def primary(self):
`replicaSet` option.

.. versionadded:: 3.0
MongoClient gained this property in version 3.0 when
MongoReplicaSetClient's functionality was merged in.
MongoClient gained this property in version 3.0.
"""
return self._topology.get_primary()

Expand All @@ -1015,8 +1014,7 @@ def secondaries(self):
client was created without the `replicaSet` option.

.. versionadded:: 3.0
MongoClient gained this property in version 3.0 when
MongoReplicaSetClient's functionality was merged in.
MongoClient gained this property in version 3.0.
"""
return self._topology.get_secondaries()

Expand Down
48 changes: 0 additions & 48 deletions pymongo/mongo_replica_set_client.py

This file was deleted.

4 changes: 2 additions & 2 deletions pymongo/read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


def _validate_tag_sets(tag_sets):
"""Validate tag sets for a MongoReplicaSetClient.
"""Validate tag sets for a MongoClient.
"""
if tag_sets is None:
return tag_sets
Expand Down Expand Up @@ -144,7 +144,7 @@ def tag_sets(self):
To specify a priority-order for tag sets, provide a list of
tag sets: ``[{'dc': 'ny'}, {'dc': 'la'}, {}]``. A final, empty tag
set, ``{}``, means "read from any member that matches the mode,
ignoring tags." MongoReplicaSetClient tries each set of tags in turn
ignoring tags." MongoClient tries each set of tags in turn
until it finds a set of tags with at least one matching member.

.. seealso:: `Data-Center Awareness
Expand Down
18 changes: 7 additions & 11 deletions test/test_gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
from bson.py3compat import StringIO, string_type
from pymongo.mongo_client import MongoClient
from pymongo.errors import (ConfigurationError,
ConnectionFailure,
NotMasterError,
ServerSelectionTimeoutError)
from pymongo.read_preferences import ReadPreference
from gridfs.errors import CorruptGridFile, FileExists, NoFile
from test.test_replica_set_client import TestReplicaSetClientBase
from test import (client_context,
unittest,
IntegrationTest)
Expand Down Expand Up @@ -487,7 +486,7 @@ def test_md5(self):
self.assertIsNone(gout.md5)


class TestGridfsReplicaSet(TestReplicaSetClientBase):
class TestGridfsReplicaSet(IntegrationTest):

@classmethod
@client_context.require_secondaries_count(1)
Expand All @@ -500,7 +499,7 @@ def tearDownClass(cls):

def test_gridfs_replica_set(self):
rsc = rs_client(
w=self.w,
w=client_context.w,
read_preference=ReadPreference.SECONDARY)

fs = gridfs.GridFS(rsc.gfsreplica, 'gfsreplicatest')
Expand All @@ -513,10 +512,7 @@ def test_gridfs_replica_set(self):
self.assertEqual(b'foo', content)

def test_gridfs_secondary(self):
primary_host, primary_port = self.primary
primary_connection = single_client(primary_host, primary_port)

secondary_host, secondary_port = one(self.secondaries)
secondary_host, secondary_port = one(self.client.secondaries)
secondary_connection = single_client(
secondary_host, secondary_port,
read_preference=ReadPreference.SECONDARY)
Expand All @@ -526,12 +522,12 @@ def test_gridfs_secondary(self):
fs = gridfs.GridFS(secondary_connection.gfsreplica, 'gfssecondarytest')

# This won't detect secondary, raises error
self.assertRaises(ConnectionFailure, fs.put, b'foo')
self.assertRaises(NotMasterError, fs.put, b'foo')

def test_gridfs_secondary_lazy(self):
# Should detect it's connected to secondary and not attempt to
# create index.
secondary_host, secondary_port = one(self.secondaries)
secondary_host, secondary_port = one(self.client.secondaries)
client = single_client(
secondary_host,
secondary_port,
Expand All @@ -543,7 +539,7 @@ def test_gridfs_secondary_lazy(self):

# Connects, doesn't create index.
self.assertRaises(NoFile, fs.get_last_version)
self.assertRaises(ConnectionFailure, fs.put, 'data')
self.assertRaises(NotMasterError, fs.put, 'data')


if __name__ == "__main__":
Expand Down
18 changes: 7 additions & 11 deletions test/test_gridfs_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
from bson.son import SON
from gridfs.errors import NoFile, CorruptGridFile
from pymongo.errors import (ConfigurationError,
ConnectionFailure,
NotMasterError,
ServerSelectionTimeoutError)
from pymongo.mongo_client import MongoClient
from pymongo.read_preferences import ReadPreference
from test import (client_context,
unittest,
IntegrationTest)
from test.test_replica_set_client import TestReplicaSetClientBase
from test.utils import (ignore_deprecations,
joinall,
one,
Expand Down Expand Up @@ -504,7 +503,7 @@ def test_md5(self):
self.assertIsNone(gout.md5)


class TestGridfsBucketReplicaSet(TestReplicaSetClientBase):
class TestGridfsBucketReplicaSet(IntegrationTest):

@classmethod
@client_context.require_secondaries_count(1)
Expand All @@ -517,7 +516,7 @@ def tearDownClass(cls):

def test_gridfs_replica_set(self):
rsc = rs_client(
w=self.w,
w=client_context.w,
read_preference=ReadPreference.SECONDARY)

gfs = gridfs.GridFSBucket(rsc.gfsbucketreplica, 'gfsbucketreplicatest')
Expand All @@ -526,10 +525,7 @@ def test_gridfs_replica_set(self):
self.assertEqual(b'foo', content)

def test_gridfs_secondary(self):
primary_host, primary_port = self.primary
primary_connection = single_client(primary_host, primary_port)

secondary_host, secondary_port = one(self.secondaries)
secondary_host, secondary_port = one(self.client.secondaries)
secondary_connection = single_client(
secondary_host, secondary_port,
read_preference=ReadPreference.SECONDARY)
Expand All @@ -540,13 +536,13 @@ def test_gridfs_secondary(self):
secondary_connection.gfsbucketreplica, 'gfsbucketsecondarytest')

# This won't detect secondary, raises error
self.assertRaises(ConnectionFailure, gfs.upload_from_stream,
self.assertRaises(NotMasterError, gfs.upload_from_stream,
"test_filename", b'foo')

def test_gridfs_secondary_lazy(self):
# Should detect it's connected to secondary and not attempt to
# create index.
secondary_host, secondary_port = one(self.secondaries)
secondary_host, secondary_port = one(self.client.secondaries)
client = single_client(
secondary_host,
secondary_port,
Expand All @@ -560,7 +556,7 @@ def test_gridfs_secondary_lazy(self):
# Connects, doesn't create index.
self.assertRaises(NoFile, gfs.open_download_stream_by_name,
"test_filename")
self.assertRaises(ConnectionFailure, gfs.upload_from_stream,
self.assertRaises(NotMasterError, gfs.upload_from_stream,
"test_filename", b'data')


Expand Down
16 changes: 8 additions & 8 deletions test/test_read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

from test import (SkipTest,
client_context,
IntegrationTest,
unittest,
db_user,
db_pwd)
from test.test_replica_set_client import TestReplicaSetClientBase
from test.utils import (connected,
ignore_deprecations,
one,
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_deepcopy(self):
self.assertEqual(pref, copy.deepcopy(pref))


class TestReadPreferencesBase(TestReplicaSetClientBase):
class TestReadPreferencesBase(IntegrationTest):

@classmethod
@client_context.require_secondaries_count(1)
Expand All @@ -100,7 +100,7 @@ def setUp(self):
self.client.pymongo_test.test.drop()
self.client.get_database(
"pymongo_test",
write_concern=WriteConcern(w=self.w)).test.insert_many(
write_concern=WriteConcern(w=client_context.w)).test.insert_many(
[{'_id': i} for i in range(10)])

self.addCleanup(self.client.pymongo_test.test.drop)
Expand Down Expand Up @@ -130,7 +130,7 @@ def read_from_which_kind(self, client):
def assertReadsFrom(self, expected, **kwargs):
c = rs_client(**kwargs)
wait_until(
lambda: len(c.nodes - c.arbiters) == self.w,
lambda: len(c.nodes - c.arbiters) == client_context.w,
"discovered all nodes")

used = self.read_from_which_kind(c)
Expand Down Expand Up @@ -284,7 +284,7 @@ def test_nearest(self):
read_preference=ReadPreference.NEAREST,
localThresholdMS=10000) # 10 seconds

data_members = set(self.hosts).difference(set(self.arbiters))
data_members = {self.client.primary} | self.client.secondaries

# This is a probabilistic test; track which members we've read from so
# far, and keep reading until we've used all the members or give up.
Expand Down Expand Up @@ -347,23 +347,23 @@ def record_a_read(self, address):
]


class TestCommandAndReadPreference(TestReplicaSetClientBase):
class TestCommandAndReadPreference(IntegrationTest):

@classmethod
@client_context.require_secondaries_count(1)
def setUpClass(cls):
super(TestCommandAndReadPreference, cls).setUpClass()
cls.c = ReadPrefTester(
client_context.pair,
replicaSet=cls.name,
replicaSet=client_context.replica_set_name,
# Ignore round trip times, to test ReadPreference modes only.
localThresholdMS=1000*1000)
if client_context.auth_enabled:
cls.c.admin.authenticate(db_user, db_pwd)
cls.client_version = Version.from_client(cls.c)
# mapReduce and group fail with no collection
coll = cls.c.pymongo_test.get_collection(
'test', write_concern=WriteConcern(w=cls.w))
'test', write_concern=WriteConcern(w=client_context.w))
coll.insert_one({})

@classmethod
Expand Down
Loading