|
31 | 31 | message) |
32 | 32 | from pymongo.bulk import BulkOperationBuilder, _Bulk |
33 | 33 | from pymongo.command_cursor import CommandCursor, RawBatchCommandCursor |
| 34 | +from pymongo.common import ORDERED_TYPES |
34 | 35 | from pymongo.collation import validate_collation_or_none |
35 | 36 | from pymongo.change_stream import ChangeStream |
36 | 37 | from pymongo.cursor import Cursor, RawBatchCursor |
|
47 | 48 | UpdateResult) |
48 | 49 | from pymongo.write_concern import WriteConcern |
49 | 50 |
|
50 | | -try: |
51 | | - from collections import OrderedDict |
52 | | - _ORDERED_TYPES = (SON, OrderedDict) |
53 | | -except ImportError: |
54 | | - _ORDERED_TYPES = (SON,) |
55 | | - |
56 | 51 | _NO_OBJ_ERROR = "No matching object found" |
57 | 52 | _UJOIN = u"%s.%s" |
58 | 53 |
|
@@ -243,7 +238,8 @@ def _command(self, sock_info, command, slave_ok=False, |
243 | 238 | write_concern=write_concern, |
244 | 239 | parse_write_concern_error=parse_write_concern_error, |
245 | 240 | collation=collation, |
246 | | - session=s) |
| 241 | + session=s, |
| 242 | + client=self.__database.client) |
247 | 243 |
|
248 | 244 | def __create(self, options, collation, session): |
249 | 245 | """Sends a create command with the given options. |
@@ -573,7 +569,8 @@ def _insert_one( |
573 | 569 | command, |
574 | 570 | codec_options=self.__write_response_codec_options, |
575 | 571 | check_keys=check_keys, |
576 | | - session=s) |
| 572 | + session=s, |
| 573 | + client=self.__database.client) |
577 | 574 | _check_write_command_response([(0, result)]) |
578 | 575 | else: |
579 | 576 | # Legacy OP_INSERT. |
@@ -811,7 +808,9 @@ def _update(self, sock_info, criteria, document, upsert=False, |
811 | 808 | self.__database.name, |
812 | 809 | command, |
813 | 810 | codec_options=self.__write_response_codec_options, |
814 | | - session=s).copy() |
| 811 | + session=s, |
| 812 | + client=self.__database.client).copy() |
| 813 | + |
815 | 814 | _check_write_command_response([(0, result)]) |
816 | 815 | # Add the updatedExisting field for compatibility. |
817 | 816 | if result.get('n') and 'upserted' not in result: |
@@ -1089,7 +1088,8 @@ def _delete( |
1089 | 1088 | self.__database.name, |
1090 | 1089 | command, |
1091 | 1090 | codec_options=self.__write_response_codec_options, |
1092 | | - session=s) |
| 1091 | + session=s, |
| 1092 | + client=self.__database.client) |
1093 | 1093 | _check_write_command_response([(0, result)]) |
1094 | 1094 | return result |
1095 | 1095 | else: |
@@ -2043,7 +2043,8 @@ def _aggregate(self, pipeline, cursor_class, first_batch_size, session, |
2043 | 2043 | parse_write_concern_error=dollar_out, |
2044 | 2044 | read_concern=read_concern, |
2045 | 2045 | collation=collation, |
2046 | | - session=session) |
| 2046 | + session=session, |
| 2047 | + client=self.__database.client) |
2047 | 2048 |
|
2048 | 2049 | if "cursor" in result: |
2049 | 2050 | cursor = result["cursor"] |
@@ -2349,8 +2350,9 @@ def rename(self, new_name, session=None, **kwargs): |
2349 | 2350 | if sock_info.max_wire_version >= 5 and self.write_concern: |
2350 | 2351 | cmd['writeConcern'] = self.write_concern.document |
2351 | 2352 | cmd.update(kwargs) |
2352 | | - sock_info.command('admin', cmd, parse_write_concern_error=True, |
2353 | | - session=s) |
| 2353 | + return sock_info.command( |
| 2354 | + 'admin', cmd, parse_write_concern_error=True, |
| 2355 | + session=s, client=self.__database.client) |
2354 | 2356 |
|
2355 | 2357 | def distinct(self, key, filter=None, session=None, **kwargs): |
2356 | 2358 | """Get a list of distinct values for `key` among all documents |
@@ -2974,7 +2976,7 @@ def find_and_modify(self, query={}, update=None, |
2974 | 2976 | kwargs['sort'] = helpers._index_document(sort) |
2975 | 2977 | # Accept OrderedDict, SON, and dict with len == 1 so we |
2976 | 2978 | # don't break existing code already using find_and_modify. |
2977 | | - elif (isinstance(sort, _ORDERED_TYPES) or |
| 2979 | + elif (isinstance(sort, ORDERED_TYPES) or |
2978 | 2980 | isinstance(sort, dict) and len(sort) == 1): |
2979 | 2981 | warnings.warn("Passing mapping types for `sort` is deprecated," |
2980 | 2982 | " use a list of (key, direction) pairs instead", |
|
0 commit comments