Merge "Add two fields to NeutronDbObjectDuplicateEntry"

This commit is contained in:
Zuul
2018-07-16 20:03:54 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 0 deletions

View File

@@ -21,6 +21,18 @@ class NeutronObjectUpdateForbidden(exceptions.NeutronException):
class NeutronDbObjectDuplicateEntry(exceptions.Conflict):
"""Duplicate entry at unique column error.
Raised when made an attempt to write to a unique column the same entry as
existing one. :attr: `columns` available on an instance of the exception
and could be used at error handling::
try:
obj_ref.save()
except NeutronDbObjectDuplicateEntry as e:
if 'colname' in e.columns:
# Handle error.
"""
message = _("Failed to create a duplicate %(object_type)s: "
"for attribute(s) %(attributes)s with value(s) %(values)s")
@@ -30,6 +42,8 @@ class NeutronDbObjectDuplicateEntry(exceptions.Conflict):
fully_qualified=False),
attributes=db_exception.columns,
values=db_exception.value)
self.columns = db_exception.columns
self.value = db_exception.value
class NeutronDbObjectNotFoundByModel(exceptions.NotFound):

View File

@@ -0,0 +1,6 @@
---
other:
- |
Add two fields ``columns`` and ``value`` to exception
``NeutronDbObjectDuplicateEntry``. These two fields are populated
from the corresponding db exception.