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

Pymongo's update_one() returns UpdateResult with AttributeError

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.1
    • Component/s: None
    • None
    • Environment:
      Linux Mint x64, MongoDB and Pymongo 3.2.1

      I just upgraded my MongoDB and Pymongo to the latest version 3.2.1 to be able to use the UpdateResult object after calling update_one(). But for some reason the returned object has one field that contains an AttributeError.

      Take a look at my Pycharm screen. You can see that UpdateResult_acknowledged appears as:
      'Traceback (most recent call last):
      File "/opt/pycharm-community-5.0.4/helpers/pydev/pydevd_resolver.py", line 191, in _getPyDictionary
      attr = getattr(var, n)
      AttributeError: UpdateResult_acknowledged'

      It causes me a problem since I am trying to catch all exceptions and every time I need to use update_one() in my code I get this exception.
      A snippet of my code is attached.

      Luckily I was able to find a workaround that doesn't cause this exception to be raised. Instead of using update_one(), I can use the deprecated function update() which returns only the RAW result from MongoDB and then instead of comparing updateResult['modified_count'], I can just compare updateResult['nModified'].

      But this is definitely not a best practice to use deprecated functions... Any thoughts?

        1. snipper.txt
          0.5 kB
        2. screen.png
          screen.png
          43 kB

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            BeePi BeePi [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: