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

find_and_modify returns OperationError instead of DuplicateKeyError

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.1
    • Affects Version/s: None
    • Component/s: None
    • None

      See example:

      import pymongo
      c = pymongo.Connection()
      db = c['test']
      
      db['test'].drop()
      db['test'].ensure_index('a', unique=True)
      
      db['test'].insert({'a': '1', 'b': 1}, safe=True)
      
      try:
          db['test'].insert({'a': '1', 'b': 2}, safe=True)
      except pymongo.errors.DuplicateKeyError:
          print 'insert gives pymongo.errors.DuplicateKeyError'
      
      try:
          db['test'].find_and_modify(query={'a': '1', 'b': 2}, update={'$set': {'c': 1}}, upsert=True)
      except pymongo.errors.DuplicateKeyError:
          print 'find_and_modify gives pymongo.errors.DuplicateKeyError'
      except pymongo.errors.OperationFailure:
          print 'find_and_modify gives pymongo.errors.OperationFailure'
      

      I would expect to get output

      insert gives pymongo.errors.DuplicateKeyError
      find_and_modify gives pymongo.errors.DuplicateKeyError
      

      but I get:

      insert gives pymongo.errors.DuplicateKeyError
      find_and_modify gives pymongo.errors.OperationFailure
      

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            davefooks David Fooks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: