Skip to content

Commit 7c1060c

Browse files
authored
PYTHON-1307 Remove SONManipulator APIs (#557)
1 parent cf877e9 commit 7c1060c

15 files changed

+72
-524
lines changed

doc/api/pymongo/collection.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
.. automethod:: aggregate
4848
.. automethod:: aggregate_raw_batches
4949
.. automethod:: watch
50-
.. automethod:: find(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, manipulate=True, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None)
51-
.. automethod:: find_raw_batches(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, manipulate=True, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None)
50+
.. automethod:: find(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None, allow_disk_use=None)
51+
.. automethod:: find_raw_batches(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, allow_disk_use=None)
5252
.. automethod:: find_one(filter=None, *args, **kwargs)
5353
.. automethod:: find_one_and_delete
5454
.. automethod:: find_one_and_replace(filter, replacement, projection=None, sort=None, return_document=ReturnDocument.BEFORE, hint=None, session=None, **kwargs)

doc/api/pymongo/cursor.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.. autoattribute:: EXHAUST
1616
:annotation:
1717

18-
.. autoclass:: pymongo.cursor.Cursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, manipulate=True, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None)
18+
.. autoclass:: pymongo.cursor.Cursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None, allow_disk_use=None)
1919
:members:
2020

2121
.. describe:: c[index]
@@ -24,4 +24,4 @@
2424

2525
.. automethod:: __getitem__
2626

27-
.. autoclass:: pymongo.cursor.RawBatchCursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None)
27+
.. autoclass:: pymongo.cursor.RawBatchCursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, modifiers=None, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, allow_disk_use=None)

doc/api/pymongo/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Sub-modules:
4747
read_concern
4848
read_preferences
4949
results
50-
son_manipulator
5150
server_api
5251
uri_parser
5352
write_concern

doc/api/pymongo/son_manipulator.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc/changelog.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Breaking Changes in 4.0
3030
- Removed :meth:`pymongo.collection.Collection.parallel_scan`.
3131
- Removed :meth:`pymongo.collection.Collection.ensure_index`.
3232
- Removed :meth:`pymongo.collection.Collection.reindex`.
33-
- Removed :meth:`pymongo.collection.Collection.save`
34-
- Removed :meth:`pymongo.collection.Collection.insert`
35-
- Removed :meth:`pymongo.collection.Collection.update`
36-
- Removed :meth:`pymongo.collection.Collection.remove`
37-
- Removed :meth:`pymongo.collection.Collection.find_and_modify`
33+
- Removed :meth:`pymongo.collection.Collection.save`.
34+
- Removed :meth:`pymongo.collection.Collection.insert`.
35+
- Removed :meth:`pymongo.collection.Collection.update`.
36+
- Removed :meth:`pymongo.collection.Collection.remove`.
37+
- Removed :meth:`pymongo.collection.Collection.find_and_modify`.
3838
- Removed :meth:`pymongo.mongo_client.MongoClient.close_cursor`. Use
3939
:meth:`pymongo.cursor.Cursor.close` instead.
4040
- Removed :meth:`pymongo.mongo_client.MongoClient.kill_cursors`.
@@ -43,6 +43,21 @@ Breaking Changes in 4.0
4343
- Removed :meth:`pymongo.mongo_client.MongoClient.set_cursor_manager`.
4444
- Removed :mod:`pymongo.thread_util`.
4545
- Removed :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient`.
46+
- Removed :mod:`pymongo.son_manipulator`,
47+
:class:`pymongo.son_manipulator.SONManipulator`,
48+
:class:`pymongo.son_manipulator.ObjectIdInjector`,
49+
:class:`pymongo.son_manipulator.ObjectIdShuffler`,
50+
:class:`pymongo.son_manipulator.AutoReference`,
51+
:class:`pymongo.son_manipulator.NamespaceInjector`,
52+
:meth:`pymongo.database.Database.add_son_manipulator`,
53+
:attr:`pymongo.database.Database.outgoing_copying_manipulators`,
54+
:attr:`pymongo.database.Database.outgoing_manipulators`,
55+
:attr:`pymongo.database.Database.incoming_copying_manipulators`, and
56+
:attr:`pymongo.database.Database.incoming_manipulators`.
57+
- Removed the ``manipulate`` parameter from
58+
:meth:`~pymongo.collection.Collection.find`,
59+
:meth:`~pymongo.collection.Collection.find_one`, and
60+
:meth:`~pymongo.cursor.Cursor`.
4661

4762
Notable improvements
4863
....................

doc/migrate-to-pymongo4.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,38 @@ can be changed to this::
274274

275275
.. _reIndex command: https://docs.mongodb.com/manual/reference/command/reIndex/
276276

277+
SONManipulator is removed
278+
-------------------------
279+
280+
Removed :mod:`pymongo.son_manipulator`,
281+
:class:`pymongo.son_manipulator.SONManipulator`,
282+
:class:`pymongo.son_manipulator.ObjectIdInjector`,
283+
:class:`pymongo.son_manipulator.ObjectIdShuffler`,
284+
:class:`pymongo.son_manipulator.AutoReference`,
285+
:class:`pymongo.son_manipulator.NamespaceInjector`,
286+
:meth:`pymongo.database.Database.add_son_manipulator`,
287+
:attr:`pymongo.database.Database.outgoing_copying_manipulators`,
288+
:attr:`pymongo.database.Database.outgoing_manipulators`,
289+
:attr:`pymongo.database.Database.incoming_copying_manipulators`, and
290+
:attr:`pymongo.database.Database.incoming_manipulators`.
291+
292+
Removed the ``manipulate`` parameter from
293+
:meth:`~pymongo.collection.Collection.find`,
294+
:meth:`~pymongo.collection.Collection.find_one`, and
295+
:meth:`~pymongo.cursor.Cursor`.
296+
297+
The :class:`pymongo.son_manipulator.SONManipulator` API has limitations as a
298+
technique for transforming your data and was deprecated in PyMongo 3.0.
299+
Instead, it is more flexible and straightforward to transform outgoing
300+
documents in your own code before passing them to PyMongo, and transform
301+
incoming documents after receiving them from PyMongo.
302+
303+
Alternatively, if your application uses the ``SONManipulator`` API to convert
304+
custom types to BSON, the :class:`~bson.codec_options.TypeCodec` and
305+
:class:`~bson.codec_options.TypeRegistry` APIs may be a suitable alternative.
306+
For more information, see the
307+
:doc:`custom type example <examples/custom_type>`.
308+
277309
Removed features with no migration path
278310
---------------------------------------
279311

pymongo/bulk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ def execute_no_results(self, sock_info, generator):
478478
sock_info,
479479
operation['q'],
480480
doc,
481-
operation['upsert'],
482-
check_keys,
483-
operation['multi'],
481+
upsert=operation['upsert'],
482+
check_keys=check_keys,
483+
multi=operation['multi'],
484484
write_concern=write_concern,
485485
op_id=op_id,
486486
ordered=self.ordered,

pymongo/collection.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,9 @@ def _legacy_write(self, sock_info, name, cmd, op_id,
554554

555555
def _insert_one(
556556
self, doc, ordered,
557-
check_keys, manipulate, write_concern, op_id, bypass_doc_val,
557+
check_keys, write_concern, op_id, bypass_doc_val,
558558
session):
559559
"""Internal helper for inserting a single document."""
560-
if manipulate:
561-
doc = self.__database._apply_incoming_manipulators(doc, self)
562-
if not isinstance(doc, RawBSONDocument) and '_id' not in doc:
563-
doc['_id'] = ObjectId()
564-
doc = self.__database._apply_incoming_copying_manipulators(doc,
565-
self)
566560
write_concern = write_concern or self.write_concern
567561
acknowledged = write_concern.acknowledged
568562
command = SON([('insert', self.name),
@@ -646,7 +640,7 @@ def insert_one(self, document, bypass_document_validation=False,
646640
write_concern = self._write_concern_for(session)
647641
return InsertOneResult(
648642
self._insert_one(
649-
document, ordered=True, check_keys=True, manipulate=False,
643+
document, ordered=True, check_keys=True,
650644
write_concern=write_concern, op_id=None,
651645
bypass_doc_val=bypass_document_validation, session=session),
652646
write_concern.acknowledged)
@@ -712,14 +706,12 @@ def gen():
712706
return InsertManyResult(inserted_ids, write_concern.acknowledged)
713707

714708
def _update(self, sock_info, criteria, document, upsert=False,
715-
check_keys=True, multi=False, manipulate=False,
709+
check_keys=True, multi=False,
716710
write_concern=None, op_id=None, ordered=True,
717711
bypass_doc_val=False, collation=None, array_filters=None,
718712
hint=None, session=None, retryable_write=False):
719713
"""Internal update / replace helper."""
720714
common.validate_boolean("upsert", upsert)
721-
if manipulate:
722-
document = self.__database._fix_incoming(document, self)
723715
collation = validate_collation_or_none(collation)
724716
write_concern = write_concern or self.write_concern
725717
acknowledged = write_concern.acknowledged
@@ -801,15 +793,15 @@ def _update(self, sock_info, criteria, document, upsert=False,
801793

802794
def _update_retryable(
803795
self, criteria, document, upsert=False,
804-
check_keys=True, multi=False, manipulate=False,
796+
check_keys=True, multi=False,
805797
write_concern=None, op_id=None, ordered=True,
806798
bypass_doc_val=False, collation=None, array_filters=None,
807799
hint=None, session=None):
808800
"""Internal update / replace helper."""
809801
def _update(session, sock_info, retryable_write):
810802
return self._update(
811803
sock_info, criteria, document, upsert=upsert,
812-
check_keys=check_keys, multi=multi, manipulate=manipulate,
804+
check_keys=check_keys, multi=multi,
813805
write_concern=write_concern, op_id=op_id, ordered=ordered,
814806
bypass_doc_val=bypass_doc_val, collation=collation,
815807
array_filters=array_filters, hint=hint, session=session,
@@ -1346,8 +1338,6 @@ def find(self, *args, **kwargs):
13461338
oplogReplay query flag. Default: False.
13471339
- `batch_size` (optional): Limits the number of documents returned in
13481340
a single batch.
1349-
- `manipulate` (optional): **DEPRECATED** - If True, apply any
1350-
outgoing SON manipulators before returning. Default: True.
13511341
- `collation` (optional): An instance of
13521342
:class:`~pymongo.collation.Collation`. This option is only supported
13531343
on MongoDB 3.4 and above.

pymongo/command_cursor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ def _try_next(self, get_more_allowed):
268268
if not len(self.__data) and not self.__killed and get_more_allowed:
269269
self._refresh()
270270
if len(self.__data):
271-
coll = self.__collection
272-
return coll.database._fix_outgoing(self.__data.popleft(), coll)
271+
return self.__data.popleft()
273272
else:
274273
return None
275274

pymongo/cursor.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, collection, filter=None, projection=None, skip=0,
108108
limit=0, no_cursor_timeout=False,
109109
cursor_type=CursorType.NON_TAILABLE,
110110
sort=None, allow_partial_results=False, oplog_replay=False,
111-
modifiers=None, batch_size=0, manipulate=True,
111+
modifiers=None, batch_size=0,
112112
collation=None, hint=None, max_scan=None, max_time_ms=None,
113113
max=None, min=None, return_key=False, show_record_id=False,
114114
snapshot=False, comment=None, session=None,
@@ -181,7 +181,6 @@ def __init__(self, collection, filter=None, projection=None, skip=0,
181181
self.__max_await_time_ms = None
182182
self.__max = max
183183
self.__min = min
184-
self.__manipulate = manipulate
185184
self.__collation = validate_collation_or_none(collation)
186185
self.__return_key = return_key
187186
self.__show_record_id = show_record_id
@@ -281,7 +280,7 @@ def _clone(self, deepcopy=True, base=None):
281280
values_to_clone = ("spec", "projection", "skip", "limit",
282281
"max_time_ms", "max_await_time_ms", "comment",
283282
"max", "min", "ordering", "explain", "hint",
284-
"batch_size", "max_scan", "manipulate",
283+
"batch_size", "max_scan",
285284
"query_flags", "modifiers", "collation", "empty",
286285
"show_record_id", "return_key", "allow_disk_use",
287286
"snapshot", "exhaust")
@@ -1198,12 +1197,7 @@ def next(self):
11981197
if self.__empty:
11991198
raise StopIteration
12001199
if len(self.__data) or self._refresh():
1201-
if self.__manipulate:
1202-
_db = self.__collection.database
1203-
return _db._fix_outgoing(self.__data.popleft(),
1204-
self.__collection)
1205-
else:
1206-
return self.__data.popleft()
1200+
return self.__data.popleft()
12071201
else:
12081202
raise StopIteration
12091203

@@ -1277,15 +1271,8 @@ def __init__(self, *args, **kwargs):
12771271
12781272
.. mongodoc:: cursors
12791273
"""
1280-
manipulate = kwargs.get('manipulate')
1281-
kwargs['manipulate'] = False
12821274
super(RawBatchCursor, self).__init__(*args, **kwargs)
12831275

1284-
# Throw only after cursor's initialized, to prevent errors in __del__.
1285-
if manipulate:
1286-
raise InvalidOperation(
1287-
"Cannot use RawBatchCursor with manipulate=True")
1288-
12891276
def _unpack_response(self, response, cursor_id, codec_options,
12901277
user_fields=None, legacy_response=False):
12911278
return response.raw_response(cursor_id)

0 commit comments

Comments
 (0)