PYTHON-4332 create_search_index only sends "type" field when provided (#1573)

This commit is contained in:
Shane Harvey 2024-04-08 11:34:51 -07:00 committed by GitHub
parent 2da8af01a6
commit 48d5a46e46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -592,7 +592,7 @@ class SearchIndexModel:
self,
definition: Mapping[str, Any],
name: Optional[str] = None,
type: Optional[str] = "search",
type: Optional[str] = None,
**kwargs: Any,
) -> None:
"""Create a Search Index instance.
@ -613,7 +613,8 @@ class SearchIndexModel:
if name is not None:
self.__document["name"] = name
self.__document["definition"] = definition
self.__document["type"] = type
if type is not None:
self.__document["type"] = type
self.__document.update(kwargs)
@property

View File

@ -62,7 +62,17 @@ class TestCreateSearchIndex(IntegrationTest):
listener.reset()
with self.assertRaises(OperationFailure):
coll.create_search_index({"definition": definition, "arbitraryOption": 1})
self.assertIn("arbitraryOption", listener.events[0].command["indexes"][0])
self.assertEqual(
{"definition": definition, "arbitraryOption": 1},
listener.events[0].command["indexes"][0],
)
listener.reset()
with self.assertRaises(OperationFailure):
coll.create_search_index({"definition": definition, "type": "search"})
self.assertEqual(
{"definition": definition, "type": "search"}, listener.events[0].command["indexes"][0]
)
class SearchIndexIntegrationBase(unittest.TestCase):