Jean-Tiare Le Bigot avatar Jean-Tiare Le Bigot committed 26d25f9

Overwriterror now inherits from ConflictErrot + changelog + doc

Comments (0)

Files changed (3)

 Changes
 -------
 
+- OverwriteError inherits from ConflictError so that ``raise_on_conflict`` always raises ``ConflictError`` while staying retro-compatible
 - fix bug #17: enforce type coercion in ``DynamoDBModel.__init__``. (thanks luckyasser)
 
 ====================

docs/api/alter.rst

 :py:meth:`~.DynamoDBModel.save` has an optional parameter ``raise_on_conflict``.
 When set to ``True``, ``save`` will ensure that:
 
-- saving a *new* object will not overwrite a pe-existing one at the same keys
+- saving a *new* object will not overwrite a pre-existing one at the same keys
 - DB object has not changed before saving when the object was read form the DB.
 
 If the first scenario occurs, :py:class:`~.OverwriteError` is raised. In all
 other cases, it is :py:class:`~.ConflictError`.
 
+Please note that :py:class:`~.ConflictError` inherits from :py:class:`~.OverwriteError`.
+If you make a distinction between both cases, ``OverwriteError`` must be the 
+first ``except`` block.
+
 .. _save-use-case:
 
 Use case: Virtual coins

dynamodb_mapper/model.py

     """
 
 
-class OverwriteError(Exception):
-    """Raised when saving a DynamoDBModel instance would overwrite something
-    in the database and we've forbidden that because we believe we're creating
-    a new one (see :meth:`DynamoDBModel.save`).
-    """
-
-
 class ConflictError(Exception):
     """Atomic edition failure.
     Raised when an Item has been changed between the read and the write operation
     """
 
 
+class OverwriteError(ConflictError):
+    """Raised when saving a DynamoDBModel instance would overwrite something
+    in the database and we've forbidden that because we believe we're creating
+    a new one (see :meth:`DynamoDBModel.save`).
+    """
+
+
 class InvalidRegionError(Exception):
     """Raised when ``set_region()`` is called with an invalid region name.
     """
             one of the original values doesn't match what is in the database
             (i.e. someone went ahead and modified the object in the DB behind
             your back), the operation fails and raises
-            :class:`ConflictError`.
+            :class:`ConflictError` or ``OverwriteError``.
 
         :raise ConflictError: Target object has changed between read and write operation
-        :raise OverwriteError: Saving a new object but it already existed
+        :raise OverwriteError: A new Item overwrites an existing one and ``raise_on_conflict=True``. Note: this exception inherits from ConflictError
         """
 
         cls = type(self)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.