Skip to content

Commit

Permalink
Prevent redundant requirement for USER and PASSWORD arguments when UR…
Browse files Browse the repository at this point in the history
…I with authentication is provided
  • Loading branch information
Jibola committed Nov 21, 2024
1 parent 84d0f04 commit 769fb6b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions django_mongodb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,19 @@ def init_connection_state(self):
super().init_connection_state()

def get_connection_params(self):
settings_dict = self.settings_dict
return {
"host": settings_dict["HOST"] or None,
"port": int(settings_dict["PORT"] or 27017),
"username": settings_dict.get("USER"),
"password": settings_dict.get("PASSWORD"),
**settings_dict["OPTIONS"],
settings_dict = {
"host": self.settings_dict["HOST"] or None,
"port": int(self.settings_dict["PORT"] or None),
**self.settings_dict["OPTIONS"],
}

if username := settings_dict.get("USER"):
settings_dict["username"] = username
if password := settings_dict.get("PASSWORD"):
settings_dict["password"] = password

return settings_dict

def get_new_connection(self, conn_params):
return MongoClient(**conn_params)

Expand Down

0 comments on commit 769fb6b

Please sign in to comment.