-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
When passing a list of strings:
["field_1", "field_2"]
to create_index instead of tuples:
[("field_1", pymongo.ASCENDING), ("field_2", pymongo.ASCENDING)]
and if the name option is not defined, then _gen_index_name throws a TypeError from line 74 of helpers.py.
TypeError: not enough arguments for format string
This occurs because the format string is trying to unpack two values from each value of the list. The unpacking fails if the values of the list are strings instead of tuples of size 2. To me, this seems undesirable as the error does not actually describe what the user did incorrectly.
The required checks are done already at the beginning of the function _index_document. One option would be to extract the checks to a new helper function. One might call the new function in the _init_ of the IndexModel class after the call to _index_list, or at the beginning of both _gen_index_name and _index_document.