From: Eric Harney Date: Mon, 11 Jan 2016 20:48:18 +0000 (-0500) Subject: Return BadRequest for invalid Unicode names X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ee79580b4f68fd0f42dc5e4b9033ea99d0f923da;p=openstack-build%2Fcinder-build.git Return BadRequest for invalid Unicode names If the database fails to insert values due to them containing Unicode that the database can't support (or other similar errors that fall under DBDataError), return an HTTP 400 Bad Request rather than HTTP 500. The following fix in oslo.db is needed for this to be most useful, but is not a requirement: https://review.openstack.org/#/c/265921/ This will need to be applied to numerous calls other than just volume_create, as well. Closes-Bug: #1393871 Partial-Bug: #1531400 Change-Id: I8f71df58082adca95c30d69eab211529025a3ab6 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 393240c3a..b56ffaafd 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1100,8 +1100,11 @@ def volume_create(context, values): volume_ref.update(values) session = get_session() - with session.begin(): - session.add(volume_ref) + try: + with session.begin(): + session.add(volume_ref) + except db_exc.DBDataError: + raise exception.Invalid() return _volume_get(context, values['id'], session=session)