Describe the bug
The count() function of FindQuery does not use a session and therefore runs outside of a specified transaction context. In the implementation, the function count_documents() of AsyncIOMotorCollection is called, but the session parameter is not set there.
Current implemenation
async def count(self) -> int:
"""
Number of found documents
:return: int
"""
return (
await self.document_model.get_motor_collection().count_documents(
self.get_filter_query()
)
)
Expected behavior
If find() is called with a session parameter, this session should be used in the count() call.
Changed implementation
This should fix the behaviour.
async def count(self) -> int:
"""
Number of found documents
:return: int
"""
return (
await self.document_model.get_motor_collection().count_documents(
self.get_filter_query(), session=self.session
)
)
Describe the bug The count() function of FindQuery does not use a session and therefore runs outside of a specified transaction context. In the implementation, the function count_documents() of AsyncIOMotorCollection is called, but the session parameter is not set there.
Current implemenation
Expected behavior If find() is called with a session parameter, this session should be used in the count() call.
Changed implementation This should fix the behaviour.