Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3524

Support passing list of strings to create_index

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.4
    • 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.

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            reuben@reuben.gr.com Reuben Gardos Reid
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: