From 3077bbf1f946c2900a8a1026bc51d3ba4e208f5d Mon Sep 17 00:00:00 2001 From: Michael Pacheco Date: Fri, 7 Apr 2023 15:09:50 -0300 Subject: [PATCH] PYTHON-3657 Allow index name explicitly set to None (#1182) Co-authored-by: Michael Pacheco --- .gitignore | 1 + pymongo/operations.py | 2 +- test/test_collection.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f7ad6563f..269a7e708 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ pymongo.egg-info/ mongocryptd.pid .idea/ .nova/ +venv/ diff --git a/pymongo/operations.py b/pymongo/operations.py index f939cd479..f73262074 100644 --- a/pymongo/operations.py +++ b/pymongo/operations.py @@ -494,7 +494,7 @@ class IndexModel(object): .. _wildcard index: https://mongodb.com/docs/master/core/index-wildcard/ """ keys = _index_list(keys) - if "name" not in kwargs: + if kwargs.get("name") is None: kwargs["name"] = _gen_index_name(keys) kwargs["key"] = _index_document(keys) collation = validate_collation_or_none(kwargs.pop("collation", None)) diff --git a/test/test_collection.py b/test/test_collection.py index 881896c84..e36d6663f 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -307,6 +307,10 @@ class TestCollection(IntegrationTest): db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)]) self.assertTrue("hello_-1_world_1" in db.test.index_information()) + db.test.drop_indexes() + db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)], name=None) + self.assertTrue("hello_-1_world_1" in db.test.index_information()) + db.test.drop() db.test.insert_one({"a": 1}) db.test.insert_one({"a": 1})