|
7 | 7 | from . import patch_function, on_import, before |
8 | 8 |
|
9 | 9 |
|
10 | | -@on_import("pymongo.collection", "pymongo", version_requirement="3.10.0") |
11 | | -def patch(m): |
12 | | - """ |
13 | | - patching pymongo.collection |
14 | | - - patches Collection.*(filter, ...) |
15 | | - - patches Collection.*(..., filter, ...) |
16 | | - - patches Collection.*(pipeline, ...) |
17 | | - - patches Collection.bulk_write |
18 | | - src: https://github.com/mongodb/mongo-python-driver/blob/98658cfd1fea42680a178373333bf27f41153759/pymongo/synchronous/collection.py#L136 |
19 | | - """ |
20 | | - # func(filter, ...) |
21 | | - patch_function(m, "Collection.replace_one", _func_filter_first) |
22 | | - patch_function(m, "Collection.update_one", _func_filter_first) |
23 | | - patch_function(m, "Collection.update_many", _func_filter_first) |
24 | | - patch_function(m, "Collection.delete_one", _func_filter_first) |
25 | | - patch_function(m, "Collection.delete_many", _func_filter_first) |
26 | | - patch_function(m, "Collection.count_documents", _func_filter_first) |
27 | | - patch_function(m, "Collection.find_one_and_delete", _func_filter_first) |
28 | | - patch_function(m, "Collection.find_one_and_replace", _func_filter_first) |
29 | | - patch_function(m, "Collection.find_one_and_update", _func_filter_first) |
30 | | - patch_function(m, "Collection.find", _func_filter_first) |
31 | | - patch_function(m, "Collection.find_raw_batches", _func_filter_first) |
32 | | - # find_one not present in list since find_one calls find function. |
33 | | - |
34 | | - # func(..., filter, ...) |
35 | | - patch_function(m, "Collection.distinct", _func_filter_second) |
36 | | - |
37 | | - # func(pipeline, ...) |
38 | | - patch_function(m, "Collection.watch", _func_pipeline) |
39 | | - patch_function(m, "Collection.aggregate", _func_pipeline) |
40 | | - patch_function(m, "Collection.aggregate_raw_batches", _func_pipeline) |
41 | | - |
42 | | - # bulk_write |
43 | | - patch_function(m, "Collection.bulk_write", _bulk_write) |
44 | | - |
45 | | - |
46 | 10 | @before |
47 | 11 | def _func_filter_first(func, instance, args, kwargs): |
48 | 12 | """Collection.func(filter, ...)""" |
@@ -97,3 +61,39 @@ def _bulk_write(func, instance, args, kwargs): |
97 | 61 | op="pymongo.collection.Collection.bulk_write", |
98 | 62 | args=(request._filter,), |
99 | 63 | ) |
| 64 | + |
| 65 | + |
| 66 | +@on_import("pymongo.collection", "pymongo", version_requirement="3.10.0") |
| 67 | +def patch(m): |
| 68 | + """ |
| 69 | + patching pymongo.collection |
| 70 | + - patches Collection.*(filter, ...) |
| 71 | + - patches Collection.*(..., filter, ...) |
| 72 | + - patches Collection.*(pipeline, ...) |
| 73 | + - patches Collection.bulk_write |
| 74 | + src: https://github.com/mongodb/mongo-python-driver/blob/98658cfd1fea42680a178373333bf27f41153759/pymongo/synchronous/collection.py#L136 |
| 75 | + """ |
| 76 | + # func(filter, ...) |
| 77 | + patch_function(m, "Collection.replace_one", _func_filter_first) |
| 78 | + patch_function(m, "Collection.update_one", _func_filter_first) |
| 79 | + patch_function(m, "Collection.update_many", _func_filter_first) |
| 80 | + patch_function(m, "Collection.delete_one", _func_filter_first) |
| 81 | + patch_function(m, "Collection.delete_many", _func_filter_first) |
| 82 | + patch_function(m, "Collection.count_documents", _func_filter_first) |
| 83 | + patch_function(m, "Collection.find_one_and_delete", _func_filter_first) |
| 84 | + patch_function(m, "Collection.find_one_and_replace", _func_filter_first) |
| 85 | + patch_function(m, "Collection.find_one_and_update", _func_filter_first) |
| 86 | + patch_function(m, "Collection.find", _func_filter_first) |
| 87 | + patch_function(m, "Collection.find_raw_batches", _func_filter_first) |
| 88 | + # find_one not present in list since find_one calls find function. |
| 89 | + |
| 90 | + # func(..., filter, ...) |
| 91 | + patch_function(m, "Collection.distinct", _func_filter_second) |
| 92 | + |
| 93 | + # func(pipeline, ...) |
| 94 | + patch_function(m, "Collection.watch", _func_pipeline) |
| 95 | + patch_function(m, "Collection.aggregate", _func_pipeline) |
| 96 | + patch_function(m, "Collection.aggregate_raw_batches", _func_pipeline) |
| 97 | + |
| 98 | + # bulk_write |
| 99 | + patch_function(m, "Collection.bulk_write", _bulk_write) |
0 commit comments