Repository: rucio/rucio
Issue: set_metadata exception handler broken

Motivation
----------

Exception from server is not properly returned to client.

[Fri Mar 16 12:12:52.483227 2018] [:error] [pid 32457:tid 140443203675904] Traceback (most recent call last):
[Fri Mar 16 12:12:52.483275 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib/python2.7/site-packages/rucio/web/rest/did.py", line 595, in POST
[Fri Mar 16 12:12:52.483300 2018] [:error] [pid 32457:tid 140443203675904]     issuer=ctx.env.get('issuer'), recursive=recursive)
[Fri Mar 16 12:12:52.483304 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib/python2.7/site-packages/rucio/api/did.py", line 243, in set_metadata
[Fri Mar 16 12:12:52.483306 2018] [:error] [pid 32457:tid 140443203675904]     return did.set_metadata(scope=scope, name=name, key=key, value=value, recursive=recursive)
[Fri Mar 16 12:12:52.483309 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib/python2.7/site-packages/rucio/db/sqla/session.py", line 347, in new_funct
[Fri Mar 16 12:12:52.483311 2018] [:error] [pid 32457:tid 140443203675904]     result = function(*args, **kwargs)
[Fri Mar 16 12:12:52.483313 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib/python2.7/site-packages/rucio/core/did.py", line 1214, in set_metadata
[Fri Mar 16 12:12:52.483316 2018] [:error] [pid 32457:tid 140443203675904]     update({key: value}, synchronize_session='fetch')
[Fri Mar 16 12:12:52.483318 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 3369, in update
[Fri Mar 16 12:12:52.483329 2018] [:error] [pid 32457:tid 140443203675904]     update_op.exec_()
[Fri Mar 16 12:12:52.483332 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1326, in exec_
[Fri Mar 16 12:12:52.483334 2018] [:error] [pid 32457:tid 140443203675904]     self._do_exec()
[Fri Mar 16 12:12:52.483336 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1484, in _do_exec
[Fri Mar 16 12:12:52.483362 2018] [:error] [pid 32457:tid 140443203675904]     values = self._resolved_values
[Fri Mar 16 12:12:52.483378 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1451, in _resolved_values
[Fri Mar 16 12:12:52.483380 2018] [:error] [pid 32457:tid 140443203675904]     desc = _entity_descriptor(self.mapper, k)
[Fri Mar 16 12:12:52.483382 2018] [:error] [pid 32457:tid 140443203675904]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/base.py", line 383, in _entity_descriptor
[Fri Mar 16 12:12:52.483384 2018] [:error] [pid 32457:tid 140443203675904]     (description, key)
[Fri Mar 16 12:12:52.483387 2018] [:error] [pid 32457:tid 140443203675904] InvalidRequestError: Entity '<class 'rucio.db.sqla.models.DataIdentifier'>' has no property 'EVENTS'
[Fri Mar 16 12:12:52.483393 2018] [:error] [pid 32457:tid 140443203675904]

Changed files:
lib/rucio/core/did.py

diff --git a/lib/rucio/core/did.py b/lib/rucio/core/did.py
index 830facd33..4f918a7d8 100644
--- a/lib/rucio/core/did.py
+++ b/lib/rucio/core/did.py
@@ -34,7 +34,7 @@ from hashlib import md5
 from re import match
 
 from sqlalchemy import and_, or_, exists, String, cast, type_coerce, JSON
-from sqlalchemy.exc import DatabaseError, IntegrityError, CompileError
+from sqlalchemy.exc import DatabaseError, IntegrityError, CompileError, InvalidRequestError
 from sqlalchemy.orm.exc import NoResultFound
 from sqlalchemy.sql import not_, func
 from sqlalchemy.sql.expression import bindparam, case, text, Insert, select, true
@@ -1237,6 +1237,8 @@ def set_metadata(scope, name, key, value, type=None, did=None,
                 update({key: value}, synchronize_session='fetch')
         except CompileError as error:
             raise exception.InvalidMetadata(error)
+        except InvalidRequestError as error:
+            raise exception.InvalidMetadata("Key %s is not accepted" % key)
 
         # propagate metadata updates to child content
         if recursive:
@@ -1254,6 +1256,8 @@ def set_metadata(scope, name, key, value, type=None, did=None,
                         update({key: value}, synchronize_session='fetch')
                 except CompileError as error:
                     raise exception.InvalidMetadata(error)
+                except InvalidRequestError as error:
+                    raise exception.InvalidMetadata("Key %s is not accepted" % key)
 
     if not rowcount:
         # check for did presence