Remove unnecessary exception handling in db api

When sqlalchemy deletes data and can't find anything to
remove it returns 0, instead of raising NoResultFound

For this reason we shouldn't handle this situations and
can remove try-except wrappers.

Change-Id: I0a6d0c00d27eaa70c51dce3837749eea6c12f5bd
This commit is contained in:
Mike Fedosin 2017-08-04 16:11:49 +03:00
parent 15f5171c25
commit e84a865916

View File

@ -623,11 +623,7 @@ def create_lock(context, lock_key, session):
stop_max_attempt_number=50)
def delete_lock(context, lock_id, session):
with session.begin():
try:
session.query(models.ArtifactLock).filter_by(id=lock_id).delete()
except orm.exc.NoResultFound:
msg = _("Cannot delete a lock with id %s.") % lock_id
raise exception.NotFound(msg)
session.query(models.ArtifactLock).filter_by(id=lock_id).delete()
@retry(retry_on_exception=_retry_on_deadlock, wait_fixed=500,
@ -663,9 +659,5 @@ def delete_blob_data(context, uri, session):
"""Delete blob data from database."""
with session.begin():
blob_data_id = uri[6:]
try:
session.query(
models.ArtifactBlobData).filter_by(id=blob_data_id).delete()
except orm.exc.NoResultFound:
msg = _("Cannot delete a blob data with id %s.") % blob_data_id
raise exception.NotFound(msg)
session.query(
models.ArtifactBlobData).filter_by(id=blob_data_id).delete()