@@ -61,9 +61,11 @@ def wrapper(data, *args, **kwargs):
6161
6262 return wrapper
6363
64- collection ._insert = with_enriched_duplicate_key_error (collection ._insert )
64+ collection ._insert = with_enriched_duplicate_key_error (
65+ collection ._insert ,
66+ )
6567 collection ._ensure_uniques = with_enriched_duplicate_key_error (
66- collection ._ensure_uniques
68+ collection ._ensure_uniques ,
6769 )
6870
6971 return collection
@@ -89,19 +91,27 @@ def _patch_iter_documents(collection):
8991 that is inherited from "str". Looks like pymongo works ok
9092 with that, so we should be too.
9193 """
92- _iter_documents = collection ._iter_documents
9394
94- def iter_documents (filter ):
95- return _iter_documents (_normalize_strings (filter ))
95+ def with_normalized_strings_in_filter (fn ):
96+ @wraps (fn )
97+ def wrapper (filter ):
98+ return fn (_normalize_strings (filter ))
9699
97- collection ._iter_documents = iter_documents
100+ return wrapper
101+
102+ collection ._iter_documents = with_normalized_strings_in_filter (
103+ collection ._iter_documents ,
104+ )
98105
99106 return collection
100107
101108
102109def _patch_collection_internals (collection ):
110+ if getattr (collection , '_patched_by_mongomock_motor' , False ):
111+ return collection
103112 collection = _patch_insert_and_ensure_uniques (collection )
104113 collection = _patch_iter_documents (collection )
114+ collection ._patched_by_mongomock_motor = True
105115 return collection
106116
107117
0 commit comments