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

ensure_index returns name of index even when index already exists

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 2.7
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Documentation states that ensure_index returns None if index already exists:

      Returns the name of the created index if an index is actually
      created. Returns ``None`` if the index already exists.

      In fact, it returns None only if index creation is cached, by pymongo itself. If it isn't cached but index already exists, it does not create it again, but still return name, not None:

              if not self.__database.connection._cached(self.__database.name,
                                                        self.__name, name):
                  return self.create_index(key_or_list, cache_for, **kwargs)
              return None
      

      (create_index never returns None, according to documentation).

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            kolen Konstantin Mochalov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: