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

ensure_index only caches a single index per database (the last created one)

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.2, 3.8
    • Affects Version/s: 3.0, 3.1, 3.2, 3.3, 3.5, 3.6, 3.7
    • Component/s: None
    • None

      Found by https://github.com/mongodb/mongo-python-driver/pull/363.

      >>> client.db.test.ensure_index("key1")
      u'key1_1'
      >>> client._MongoClient__index_cache
      {u'db': {u'test': {u'key1_1': datetime.datetime(2018, 7, 24, 20, 41, 15, 406487)}}}
      >>> client.db.test.ensure_index("key2")
      u'key2_1'
      >>> client._MongoClient__index_cache
      {u'db': {u'test': {u'key2_1': datetime.datetime(2018, 7, 24, 20, 41, 29, 681537)}}}
      

      This bug was introduced in PyMongo 3.0 (by this commit).

      Note this has no effect on correctness. The only side effect is that an application that calls ensure_index on different indexes multiple times (on the same database) will unnecessarily send multiple createIndex commands to the server.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: