From 769fb6b0846f53c0aa9294c4ea1845e2ddc2cd32 Mon Sep 17 00:00:00 2001 From: Jib Date: Thu, 21 Nov 2024 15:19:32 -0500 Subject: [PATCH 1/2] Prevent redundant requirement for USER and PASSWORD arguments when URI with authentication is provided --- django_mongodb/base.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/django_mongodb/base.py b/django_mongodb/base.py index a3f4379dc..24f609e53 100644 --- a/django_mongodb/base.py +++ b/django_mongodb/base.py @@ -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) From 0b04dd37131f640c189dd83f0f07f2c1fb5674f1 Mon Sep 17 00:00:00 2001 From: Jib Date: Fri, 22 Nov 2024 09:11:49 -0500 Subject: [PATCH 2/2] fix int casting --- django_mongodb/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_mongodb/base.py b/django_mongodb/base.py index 24f609e53..c099e34da 100644 --- a/django_mongodb/base.py +++ b/django_mongodb/base.py @@ -159,7 +159,7 @@ def init_connection_state(self): def get_connection_params(self): settings_dict = { "host": self.settings_dict["HOST"] or None, - "port": int(self.settings_dict["PORT"] or None), + "port": int(self.settings_dict["PORT"] or 27017), **self.settings_dict["OPTIONS"], }