]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return BadRequest for invalid Unicode names
authorEric Harney <eharney@redhat.com>
Mon, 11 Jan 2016 20:48:18 +0000 (15:48 -0500)
committerEric Harney <eharney@redhat.com>
Mon, 11 Jan 2016 20:57:28 +0000 (15:57 -0500)
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

cinder/db/sqlalchemy/api.py

index 393240c3acd8a8b95dc0d350621ce5c644f3554c..b56ffaafd4a1b4f7f90cd76092c2eb1a384f807b 100644 (file)
@@ -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)