We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61cf36e commit f9b6218Copy full SHA for f9b6218
1 file changed
mongoengine/connection.py
@@ -248,9 +248,11 @@ def disconnect(alias=DEFAULT_CONNECTION_NAME):
248
249
connection = _connections.pop(alias, None)
250
if connection:
251
- # Only close the client if we're removing the final reference.
252
- # Use 'is' instead of 'in' or '==' to ensure the clients are
253
- # the same instance.
+ # MongoEngine may share the same MongoClient across multiple aliases
+ # if connection settings are the same so we only close
+ # the client if we're removing the final reference.
254
+ # Important to use 'is' instead of '==' because clients connected to the same cluster
255
+ # will compare equal even with different options
256
if all(connection is not c for c in _connections.values()):
257
connection.close()
258
0 commit comments