-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
The CRUD API requires two exception types for write operations like insert_one, update_one, update_many, delete_one, and delete_many - WriteError and WriteConcernError. We can accomplish this in PyMongo without breaking existing APIs and apps by tweaking the inheritance hierarchy:
- WriteError and WriteConcernError will be introduced, inheriting from OperationFailure.
- DuplicateKeyError will inherit from WriteError instead of directly from OperationFailure. WTimeoutError will inherit from WriteConcernError instead of directly from OperationFailure.
- Other write errors will be raised as WriteError. Other write concern errors will be raise as WriteConcernError. (Assuming they can be differentiated from server results.)
Applications can choose the level of granularity they want to use when catching these exceptions. Some applications may want to deal with DuplicateKeyError differently from generic WriteError. Some applications may want to deal with WTimeoutError differently from generic WriteConcernError.