Skip to content

Commit 64890ad

Browse files
SavingFrametimgraham
authored andcommitted
fix username/password authentication
database.authenticate() was removed in PyMongo 4.
1 parent 1c0706b commit 64890ad

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

django_mongodb/base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from django.core.exceptions import ImproperlyConfigured
21
from django.db.backends.base.base import BaseDatabaseWrapper
32
from django.db.backends.signals import connection_created
43
from pymongo.collection import Collection
@@ -161,17 +160,14 @@ def _connect(self):
161160
self.connection = MongoClient(
162161
host=settings_dict["HOST"] or None,
163162
port=int(settings_dict["PORT"] or 27017),
163+
username=settings_dict.get("USER"),
164+
password=settings_dict.get("PASSWORD"),
164165
**settings_dict["OPTIONS"],
165166
)
166167
db_name = settings_dict["NAME"]
167168
if db_name:
168169
self.database = self.connection[db_name]
169170

170-
user = settings_dict["USER"]
171-
password = settings_dict["PASSWORD"]
172-
if user and password and not self.database.authenticate(user, password):
173-
raise ImproperlyConfigured("Invalid username or password.")
174-
175171
self.connected = True
176172
connection_created.send(sender=self.__class__, connection=self)
177173

0 commit comments

Comments
 (0)