Skip to content

Commit 749ab89

Browse files
committed
move session to instance variable; clear commit hooks in close_pool()
1 parent 4eb66e9 commit 749ab89

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

django_mongodb_backend/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
from django.core.exceptions import ImproperlyConfigured
5+
from django.db import DEFAULT_DB_ALIAS
56
from django.db.backends.base.base import BaseDatabaseWrapper
67
from django.db.backends.utils import debug_transaction
78
from django.utils.asyncio import async_unsafe
@@ -140,7 +141,10 @@ def _isnull_operator(a, b):
140141
introspection_class = DatabaseIntrospection
141142
ops_class = DatabaseOperations
142143
validation_class = DatabaseValidation
143-
session = None
144+
145+
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS):
146+
super().__init__(settings_dict, alias=alias)
147+
self.session = None
144148

145149
def get_collection(self, name, **kwargs):
146150
collection = Collection(self.database, name, **kwargs)
@@ -237,6 +241,9 @@ def close(self):
237241

238242
def close_pool(self):
239243
"""Close the MongoClient."""
244+
# Clear commit hooks and session.
245+
self.run_on_commit = []
246+
self.session = None
240247
connection = self.connection
241248
if connection is None:
242249
return

0 commit comments

Comments
 (0)