Skip to content

Commit 769fb6b

Browse files
committed
Prevent redundant requirement for USER and PASSWORD arguments when URI with authentication is provided
1 parent 84d0f04 commit 769fb6b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

django_mongodb/base.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ def init_connection_state(self):
157157
super().init_connection_state()
158158

159159
def get_connection_params(self):
160-
settings_dict = self.settings_dict
161-
return {
162-
"host": settings_dict["HOST"] or None,
163-
"port": int(settings_dict["PORT"] or 27017),
164-
"username": settings_dict.get("USER"),
165-
"password": settings_dict.get("PASSWORD"),
166-
**settings_dict["OPTIONS"],
160+
settings_dict = {
161+
"host": self.settings_dict["HOST"] or None,
162+
"port": int(self.settings_dict["PORT"] or None),
163+
**self.settings_dict["OPTIONS"],
167164
}
168165

166+
if username := settings_dict.get("USER"):
167+
settings_dict["username"] = username
168+
if password := settings_dict.get("PASSWORD"):
169+
settings_dict["password"] = password
170+
171+
return settings_dict
172+
169173
def get_new_connection(self, conn_params):
170174
return MongoClient(**conn_params)
171175

0 commit comments

Comments
 (0)