Skip to content

Commit bfc9a70

Browse files
committed
Don't check session._leave_alive twice
1 parent f5495ca commit bfc9a70

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

pymongo/asynchronous/command_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async def _die_lock(self) -> None:
240240
self._sock_mgr = None
241241

242242
def _end_session(self) -> None:
243-
if self._session and self._session._implicit and not self._session._leave_alive:
243+
if self._session and self._session._implicit:
244244
self._session._attached_to_cursor = False
245245
self._session._end_implicit_session()
246246
self._session = None

pymongo/asynchronous/database.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,12 +1208,10 @@ async def _list_collection_names(
12081208
if not filter or (len(filter) == 1 and "name" in filter):
12091209
kwargs["nameOnly"] = True
12101210

1211-
cursor = await self._list_collections_helper(session=session, **kwargs)
1212-
results = [result["name"] async for result in cursor]
1213-
1214-
await cursor.close()
1215-
1216-
return results
1211+
return [
1212+
result["name"]
1213+
async for result in await self._list_collections_helper(session=session, **kwargs)
1214+
]
12171215

12181216
async def list_collection_names(
12191217
self,

pymongo/synchronous/command_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _die_lock(self) -> None:
240240
self._sock_mgr = None
241241

242242
def _end_session(self) -> None:
243-
if self._session and self._session._implicit and not self._session._leave_alive:
243+
if self._session and self._session._implicit:
244244
self._session._attached_to_cursor = False
245245
self._session._end_implicit_session()
246246
self._session = None

pymongo/synchronous/database.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,12 +1202,9 @@ def _list_collection_names(
12021202
if not filter or (len(filter) == 1 and "name" in filter):
12031203
kwargs["nameOnly"] = True
12041204

1205-
cursor = self._list_collections_helper(session=session, **kwargs)
1206-
results = [result["name"] for result in cursor]
1207-
1208-
cursor.close()
1209-
1210-
return results
1205+
return [
1206+
result["name"] for result in self._list_collections_helper(session=session, **kwargs)
1207+
]
12111208

12121209
def list_collection_names(
12131210
self,

0 commit comments

Comments
 (0)