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

Add an option to ignore TimeoutError exception

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible

      PyMongo always raises TimeoutError when you get wtimeout error from server due to w=... and wtimeout=... options in write operations. As for me it's almost always not the thing I'd want to get. I need an ability to ignore TimeoutError to inspect a getLastError object returned by the server like this:

      try:
          result = collection("foo").update(
              { "_id": "bar", "locked": { "$ne": True } },
              { "$set": { "locked": True } }, w="majority", wtimeout=...)
      
          if result["updatedExisting"]:
              log("The document is locked.")
      
              if result.get("wtimeout"):
                  log("The changes are successfully written to primary, but not to majority.")
              else:
                  log("The changes are successfully written to majority.")
      except Exception:
          log("Failed to lock the document.")
      
      try:
          result = collection("foo").insert(..., w="majority" wtimeout=..., full_response=True)
      
          if result.get("wtimeout"):
              log("The changes are successfully written to primary, but not to majority.")
          else:
              log("The changes are successfully written to majority.")
      except Exception:
          log("Failed to insert the document.")
      

      I'll send a pull request that adds an ability to ignore TimeoutError and obtain a getLastError object like in the above example. I hope you'll consider to apply it.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            konishchev Dmitry Konishchev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: