PYTHON-3657 Allow index name explicitly set to None (#1182)

Co-authored-by: Michael Pacheco <michael.dias@luizalabs.com>
This commit is contained in:
Michael Pacheco 2023-04-07 15:09:50 -03:00 committed by GitHub
parent acc6605ea1
commit 3077bbf1f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@ pymongo.egg-info/
mongocryptd.pid
.idea/
.nova/
venv/

View File

@ -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))

View File

@ -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})