From f72727c5c70fe9e3b6c2a0878daff3673d68b330 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 15 Jan 2025 09:41:49 -0600 Subject: [PATCH 1/3] Add docs about connection string handling --- docs/index.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 5357915..b35c7a4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -93,6 +93,12 @@ You can configure Flask-PyMongo either by passing a `MongoDB URI ``MONGO_URI`` `Flask configuration variable `_ +.. note:: + + Flask-PyMongo passes the connection string directly to PyMongo, so all behavior about interpretation of the connection string is determined by PyMongo itself. + See the Connection String examples on the `PyMongo docs `_ for more information. + + The :class:`~flask_pymongo.PyMongo` instance also accepts these additional customization options: From 5b49ba5975eaa5bd985e3f40858b091d732b7225 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 15 Jan 2025 09:44:42 -0600 Subject: [PATCH 2/3] fix task teardown --- tests/test_config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index ddf5fe3..fdfe586 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -48,8 +48,9 @@ def test_config_with_uri_in_flask_conf_var(self): mongo = flask_pymongo.PyMongo(self.app, connect=True) _wait_until_connected(mongo) - assert mongo.db is not None assert mongo.cx is not None + self.addCleanup(mongo.cx.close) + assert mongo.db is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -62,8 +63,9 @@ def test_config_with_uri_passed_directly(self): mongo = flask_pymongo.PyMongo(self.app, uri, connect=True) _wait_until_connected(mongo) - assert mongo.db is not None assert mongo.cx is not None + self.addCleanup(mongo.cx.close) + assert mongo.db is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -91,6 +93,8 @@ class CustomDict(dict[str, Any]): uri = f"mongodb://localhost:{self.port}/{self.dbname}" mongo = flask_pymongo.PyMongo(self.app, uri, document_class=CustomDict) + assert mongo.cx is not None + self.addCleanup(mongo.cx.close) assert mongo.db is not None assert mongo.db.things.find_one() is None, "precondition failed" From 1fa7b9e6cd959b55f4f10e0fd7d9c0409eadc2a3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 15 Jan 2025 09:45:54 -0600 Subject: [PATCH 3/3] Revert "fix task teardown" This reverts commit 5b49ba5975eaa5bd985e3f40858b091d732b7225. --- tests/test_config.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index fdfe586..ddf5fe3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -48,9 +48,8 @@ def test_config_with_uri_in_flask_conf_var(self): mongo = flask_pymongo.PyMongo(self.app, connect=True) _wait_until_connected(mongo) - assert mongo.cx is not None - self.addCleanup(mongo.cx.close) assert mongo.db is not None + assert mongo.cx is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -63,9 +62,8 @@ def test_config_with_uri_passed_directly(self): mongo = flask_pymongo.PyMongo(self.app, uri, connect=True) _wait_until_connected(mongo) - assert mongo.cx is not None - self.addCleanup(mongo.cx.close) assert mongo.db is not None + assert mongo.cx is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -93,8 +91,6 @@ class CustomDict(dict[str, Any]): uri = f"mongodb://localhost:{self.port}/{self.dbname}" mongo = flask_pymongo.PyMongo(self.app, uri, document_class=CustomDict) - assert mongo.cx is not None - self.addCleanup(mongo.cx.close) assert mongo.db is not None assert mongo.db.things.find_one() is None, "precondition failed"