Skip to content

Commit 9b9cf73

Browse files
authored
PYTHON-4758 - Only emit warnings for unclosed clients after opening (#1856)
1 parent 0ca926c commit 9b9cf73

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ def __getitem__(self, name: str) -> database.AsyncDatabase[_DocumentType]:
11851185
def __del__(self) -> None:
11861186
"""Check that this AsyncMongoClient has been closed and issue a warning if not."""
11871187
try:
1188-
if not self._closed:
1188+
if self._opened and not self._closed:
11891189
warnings.warn(
11901190
(
11911191
f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}"

pymongo/synchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ def __getitem__(self, name: str) -> database.Database[_DocumentType]:
11851185
def __del__(self) -> None:
11861186
"""Check that this MongoClient has been closed and issue a warning if not."""
11871187
try:
1188-
if not self._closed:
1188+
if self._opened and not self._closed:
11891189
warnings.warn(
11901190
(
11911191
f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}"

0 commit comments

Comments
 (0)