-
Type: New Feature
-
Resolution: Duplicate
-
Priority: 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.