23
23
24
24
from bson import DBRef , ObjectId
25
25
from lazy_model import LazyModel
26
+ from motor .motor_asyncio import AsyncIOMotorClientSession
26
27
from pydantic import (
27
28
ConfigDict ,
28
29
Field ,
32
33
from pydantic .class_validators import root_validator
33
34
from pydantic .main import BaseModel
34
35
from pymongo import InsertOne
35
- from pymongo .client_session import ClientSession
36
36
from pymongo .errors import DuplicateKeyError
37
37
from pymongo .results import (
38
38
DeleteResult ,
@@ -249,7 +249,7 @@ def fill_back_refs(cls, values):
249
249
async def get (
250
250
cls : Type ["DocType" ],
251
251
document_id : Any ,
252
- session : Optional [ClientSession ] = None ,
252
+ session : Optional [AsyncIOMotorClientSession ] = None ,
253
253
ignore_cache : bool = False ,
254
254
fetch_links : bool = False ,
255
255
with_children : bool = False ,
@@ -261,7 +261,7 @@ async def get(
261
261
Get document by id, returns None if document does not exist
262
262
263
263
:param document_id: PydanticObjectId - document id
264
- :param session: Optional[ClientSession ] - pymongo session
264
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session
265
265
:param ignore_cache: bool - ignore cache (if it is turned on)
266
266
:param **pymongo_kwargs: pymongo native parameters for find operation
267
267
:return: Union["Document", None]
@@ -327,7 +327,7 @@ async def insert(
327
327
self : DocType ,
328
328
* ,
329
329
link_rule : WriteRules = WriteRules .DO_NOTHING ,
330
- session : Optional [ClientSession ] = None ,
330
+ session : Optional [AsyncIOMotorClientSession ] = None ,
331
331
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
332
332
) -> DocType :
333
333
"""
@@ -383,7 +383,7 @@ async def insert(
383
383
384
384
async def create (
385
385
self : DocType ,
386
- session : Optional [ClientSession ] = None ,
386
+ session : Optional [AsyncIOMotorClientSession ] = None ,
387
387
) -> DocType :
388
388
"""
389
389
The same as self.insert()
@@ -395,14 +395,14 @@ async def create(
395
395
async def insert_one (
396
396
cls : Type [DocType ],
397
397
document : DocType ,
398
- session : Optional [ClientSession ] = None ,
398
+ session : Optional [AsyncIOMotorClientSession ] = None ,
399
399
bulk_writer : Optional ["BulkWriter" ] = None ,
400
400
link_rule : WriteRules = WriteRules .DO_NOTHING ,
401
401
) -> Optional [DocType ]:
402
402
"""
403
403
Insert one document to the collection
404
404
:param document: Document - document to insert
405
- :param session: ClientSession - pymongo session
405
+ :param session: AsyncIOMotorClientSession - motor session
406
406
:param bulk_writer: "BulkWriter" - Beanie bulk writer
407
407
:param link_rule: InsertRules - hot to manage link fields
408
408
:return: DocType
@@ -435,15 +435,15 @@ async def insert_one(
435
435
async def insert_many (
436
436
cls : Type [DocType ],
437
437
documents : Iterable [DocType ],
438
- session : Optional [ClientSession ] = None ,
438
+ session : Optional [AsyncIOMotorClientSession ] = None ,
439
439
link_rule : WriteRules = WriteRules .DO_NOTHING ,
440
440
** pymongo_kwargs ,
441
441
) -> InsertManyResult :
442
442
"""
443
443
Insert many documents to the collection
444
444
445
445
:param documents: List["Document"] - documents to insert
446
- :param session: ClientSession - pymongo session
446
+ :param session: AsyncIOMotorClientSession - motor session
447
447
:param link_rule: InsertRules - how to manage link fields
448
448
:return: InsertManyResult
449
449
"""
@@ -469,15 +469,15 @@ async def insert_many(
469
469
async def replace (
470
470
self : DocType ,
471
471
ignore_revision : bool = False ,
472
- session : Optional [ClientSession ] = None ,
472
+ session : Optional [AsyncIOMotorClientSession ] = None ,
473
473
bulk_writer : Optional [BulkWriter ] = None ,
474
474
link_rule : WriteRules = WriteRules .DO_NOTHING ,
475
475
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
476
476
) -> DocType :
477
477
"""
478
478
Fully update the document in the database
479
479
480
- :param session: Optional[ClientSession ] - pymongo session.
480
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session.
481
481
:param ignore_revision: bool - do force replace.
482
482
Used when revision based protection is turned on.
483
483
:param bulk_writer: "BulkWriter" - Beanie bulk writer
@@ -551,7 +551,7 @@ async def replace(
551
551
@validate_self_before
552
552
async def save (
553
553
self : DocType ,
554
- session : Optional [ClientSession ] = None ,
554
+ session : Optional [AsyncIOMotorClientSession ] = None ,
555
555
link_rule : WriteRules = WriteRules .DO_NOTHING ,
556
556
ignore_revision : bool = False ,
557
557
** kwargs ,
@@ -560,7 +560,7 @@ async def save(
560
560
Update an existing model in the database or
561
561
insert it if it does not yet exist.
562
562
563
- :param session: Optional[ClientSession ] - pymongo session.
563
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session.
564
564
:param link_rule: WriteRules - rules how to deal with links on writing
565
565
:param ignore_revision: bool - do force save.
566
566
:return: None
@@ -633,7 +633,7 @@ async def save(
633
633
async def save_changes (
634
634
self : DocType ,
635
635
ignore_revision : bool = False ,
636
- session : Optional [ClientSession ] = None ,
636
+ session : Optional [AsyncIOMotorClientSession ] = None ,
637
637
bulk_writer : Optional [BulkWriter ] = None ,
638
638
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
639
639
) -> Optional [DocType ]:
@@ -668,13 +668,13 @@ async def save_changes(
668
668
async def replace_many (
669
669
cls : Type [DocType ],
670
670
documents : List [DocType ],
671
- session : Optional [ClientSession ] = None ,
671
+ session : Optional [AsyncIOMotorClientSession ] = None ,
672
672
) -> None :
673
673
"""
674
674
Replace list of documents
675
675
676
676
:param documents: List["Document"]
677
- :param session: Optional[ClientSession ] - pymongo session.
677
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session.
678
678
:return: None
679
679
"""
680
680
ids_list = [document .id for document in documents ]
@@ -694,7 +694,7 @@ async def update(
694
694
self ,
695
695
* args ,
696
696
ignore_revision : bool = False ,
697
- session : Optional [ClientSession ] = None ,
697
+ session : Optional [AsyncIOMotorClientSession ] = None ,
698
698
bulk_writer : Optional [BulkWriter ] = None ,
699
699
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
700
700
skip_sync : Optional [bool ] = None ,
@@ -704,7 +704,7 @@ async def update(
704
704
Partially update the document in the database
705
705
706
706
:param args: *Union[dict, Mapping] - the modifications to apply.
707
- :param session: ClientSession - pymongo session.
707
+ :param session: AsyncIOMotorClientSession - motor session.
708
708
:param ignore_revision: bool - force update. Will update even if revision id is not the same, as stored
709
709
:param bulk_writer: "BulkWriter" - Beanie bulk writer
710
710
:param pymongo_kwargs: pymongo native parameters for update operation
@@ -749,15 +749,15 @@ async def update(
749
749
def update_all (
750
750
cls ,
751
751
* args : Union [dict , Mapping ],
752
- session : Optional [ClientSession ] = None ,
752
+ session : Optional [AsyncIOMotorClientSession ] = None ,
753
753
bulk_writer : Optional [BulkWriter ] = None ,
754
754
** pymongo_kwargs ,
755
755
) -> UpdateMany :
756
756
"""
757
757
Partially update all the documents
758
758
759
759
:param args: *Union[dict, Mapping] - the modifications to apply.
760
- :param session: ClientSession - pymongo session.
760
+ :param session: AsyncIOMotorClientSession - motor session.
761
761
:param bulk_writer: "BulkWriter" - Beanie bulk writer
762
762
:param **pymongo_kwargs: pymongo native parameters for find operation
763
763
:return: UpdateMany query
@@ -769,7 +769,7 @@ def update_all(
769
769
def set (
770
770
self : DocType ,
771
771
expression : Dict [Union [ExpressionField , str , Any ], Any ],
772
- session : Optional [ClientSession ] = None ,
772
+ session : Optional [AsyncIOMotorClientSession ] = None ,
773
773
bulk_writer : Optional [BulkWriter ] = None ,
774
774
skip_sync : Optional [bool ] = None ,
775
775
** kwargs ,
@@ -792,7 +792,7 @@ class Sample(Document):
792
792
793
793
:param expression: Dict[Union[ExpressionField, str, Any], Any] - keys and
794
794
values to set
795
- :param session: Optional[ClientSession ] - pymongo session
795
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session
796
796
:param bulk_writer: Optional[BulkWriter] - bulk writer
797
797
:param skip_sync: bool - skip doc syncing. Available for the direct instances only
798
798
:return: self
@@ -808,7 +808,7 @@ class Sample(Document):
808
808
def current_date (
809
809
self ,
810
810
expression : Dict [Union [datetime , ExpressionField , str ], Any ],
811
- session : Optional [ClientSession ] = None ,
811
+ session : Optional [AsyncIOMotorClientSession ] = None ,
812
812
bulk_writer : Optional [BulkWriter ] = None ,
813
813
skip_sync : Optional [bool ] = None ,
814
814
** kwargs ,
@@ -819,7 +819,7 @@ def current_date(
819
819
Uses [CurrentDate operator](operators/update.md#currentdate)
820
820
821
821
:param expression: Dict[Union[datetime, ExpressionField, str], Any]
822
- :param session: Optional[ClientSession ] - pymongo session
822
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session
823
823
:param bulk_writer: Optional[BulkWriter] - bulk writer
824
824
:param skip_sync: bool - skip doc syncing. Available for the direct instances only
825
825
:return: self
@@ -835,7 +835,7 @@ def current_date(
835
835
def inc (
836
836
self ,
837
837
expression : Dict [Union [ExpressionField , float , int , str ], Any ],
838
- session : Optional [ClientSession ] = None ,
838
+ session : Optional [AsyncIOMotorClientSession ] = None ,
839
839
bulk_writer : Optional [BulkWriter ] = None ,
840
840
skip_sync : Optional [bool ] = None ,
841
841
** kwargs ,
@@ -857,7 +857,7 @@ class Sample(Document):
857
857
Uses [Inc operator](operators/update.md#inc)
858
858
859
859
:param expression: Dict[Union[ExpressionField, float, int, str], Any]
860
- :param session: Optional[ClientSession ] - pymongo session
860
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session
861
861
:param bulk_writer: Optional[BulkWriter] - bulk writer
862
862
:param skip_sync: bool - skip doc syncing. Available for the direct instances only
863
863
:return: self
@@ -873,7 +873,7 @@ class Sample(Document):
873
873
@wrap_with_actions (EventTypes .DELETE )
874
874
async def delete (
875
875
self ,
876
- session : Optional [ClientSession ] = None ,
876
+ session : Optional [AsyncIOMotorClientSession ] = None ,
877
877
bulk_writer : Optional [BulkWriter ] = None ,
878
878
link_rule : DeleteRules = DeleteRules .DO_NOTHING ,
879
879
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
@@ -882,7 +882,7 @@ async def delete(
882
882
"""
883
883
Delete the document
884
884
885
- :param session: Optional[ClientSession ] - pymongo session.
885
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session.
886
886
:param bulk_writer: "BulkWriter" - Beanie bulk writer
887
887
:param link_rule: DeleteRules - rules for link fields
888
888
:param **pymongo_kwargs: pymongo native parameters for delete operation
@@ -930,14 +930,14 @@ async def delete(
930
930
@classmethod
931
931
async def delete_all (
932
932
cls ,
933
- session : Optional [ClientSession ] = None ,
933
+ session : Optional [AsyncIOMotorClientSession ] = None ,
934
934
bulk_writer : Optional [BulkWriter ] = None ,
935
935
** pymongo_kwargs ,
936
936
) -> Optional [DeleteResult ]:
937
937
"""
938
938
Delete all the documents
939
939
940
- :param session: Optional[ClientSession ] - pymongo session.
940
+ :param session: Optional[AsyncIOMotorClientSession ] - motor session.
941
941
:param bulk_writer: "BulkWriter" - Beanie bulk writer
942
942
:param **pymongo_kwargs: pymongo native parameters for delete operation
943
943
:return: Optional[DeleteResult] - pymongo DeleteResult instance.
@@ -1112,7 +1112,7 @@ def get_settings(cls) -> DocumentSettings:
1112
1112
1113
1113
@classmethod
1114
1114
async def inspect_collection (
1115
- cls , session : Optional [ClientSession ] = None
1115
+ cls , session : Optional [AsyncIOMotorClientSession ] = None
1116
1116
) -> InspectionResult :
1117
1117
"""
1118
1118
Check, if documents, stored in the MongoDB collection
@@ -1202,7 +1202,7 @@ async def distinct(
1202
1202
cls ,
1203
1203
key : str ,
1204
1204
filter : Optional [Mapping [str , Any ]] = None ,
1205
- session : Optional [ClientSession ] = None ,
1205
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1206
1206
** kwargs : Any ,
1207
1207
) -> list :
1208
1208
return await cls .get_motor_collection ().distinct (
@@ -1223,7 +1223,7 @@ def is_deleted(self) -> bool:
1223
1223
1224
1224
async def hard_delete (
1225
1225
self ,
1226
- session : Optional [ClientSession ] = None ,
1226
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1227
1227
bulk_writer : Optional [BulkWriter ] = None ,
1228
1228
link_rule : DeleteRules = DeleteRules .DO_NOTHING ,
1229
1229
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
@@ -1239,7 +1239,7 @@ async def hard_delete(
1239
1239
1240
1240
async def delete (
1241
1241
self ,
1242
- session : Optional [ClientSession ] = None ,
1242
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1243
1243
bulk_writer : Optional [BulkWriter ] = None ,
1244
1244
link_rule : DeleteRules = DeleteRules .DO_NOTHING ,
1245
1245
skip_actions : Optional [List [Union [ActionDirections , str ]]] = None ,
@@ -1257,7 +1257,7 @@ def find_many_in_all( # type: ignore
1257
1257
skip : Optional [int ] = None ,
1258
1258
limit : Optional [int ] = None ,
1259
1259
sort : Union [None , str , List [Tuple [str , SortDirection ]]] = None ,
1260
- session : Optional [ClientSession ] = None ,
1260
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1261
1261
ignore_cache : bool = False ,
1262
1262
fetch_links : bool = False ,
1263
1263
with_children : bool = False ,
@@ -1289,7 +1289,7 @@ def find_many( # type: ignore
1289
1289
skip : Optional [int ] = None ,
1290
1290
limit : Optional [int ] = None ,
1291
1291
sort : Union [None , str , List [Tuple [str , SortDirection ]]] = None ,
1292
- session : Optional [ClientSession ] = None ,
1292
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1293
1293
ignore_cache : bool = False ,
1294
1294
fetch_links : bool = False ,
1295
1295
with_children : bool = False ,
@@ -1321,7 +1321,7 @@ def find_one( # type: ignore
1321
1321
cls : Type [FindType ],
1322
1322
* args : Union [Mapping [str , Any ], bool ],
1323
1323
projection_model : Optional [Type ["DocumentProjectionType" ]] = None ,
1324
- session : Optional [ClientSession ] = None ,
1324
+ session : Optional [AsyncIOMotorClientSession ] = None ,
1325
1325
ignore_cache : bool = False ,
1326
1326
fetch_links : bool = False ,
1327
1327
with_children : bool = False ,
0 commit comments