Return BadRequest for invalid 4byte unicode character

If the database fails to insert values containing
4byte unicode character that the database can't support
(or other similar errors that fall under DBDataError),
return an HTTP 400 Bad Request rather than HTTP 500.

This patch fixes:

1. volume image-metadata
2. volume metadata
3. volume metadata-update-all
4. snapshot-metadata
5. snapshot-metadata-update-all
6. volume transfer-create

APIImpact: For all of the above APIs, it will return 400 error instead
of 500 if user passes 4 byte unicode character in the request.

Closes-Bug: #1583528
Change-Id: I50d873d4de226cb12ca4f8c4ce38dca3d2fab494
This commit is contained in:
bhagyashris
2016-03-15 11:48:13 +00:00
parent fce7fec777
commit 3e3e7b667c

View File

@@ -2066,6 +2066,7 @@ def volume_metadata_delete(context, volume_id, key, meta_type):
@require_context
@require_volume_exists
@handle_db_data_error
@_retry_on_deadlock
def volume_metadata_update(context, volume_id, metadata, delete, meta_type):
if meta_type == common.METADATA_TYPES.user:
@@ -2436,6 +2437,7 @@ def _snapshot_metadata_get_item(context, snapshot_id, key, session=None):
@require_context
@require_snapshot_exists
@handle_db_data_error
@_retry_on_deadlock
def snapshot_metadata_update(context, snapshot_id, metadata, delete):
session = get_session()
@@ -3862,6 +3864,7 @@ def transfer_get_all_by_project(context, project_id):
@require_context
@handle_db_data_error
def transfer_create(context, values):
if not values.get('id'):
values['id'] = str(uuid.uuid4())