Commits

Anonymous committed 26d25f9 Draft

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)