Repository: rucio/rucio

Issue:
get_dataset_locks_by_rse throws exception if RSE is empty


```
Setting up rucio 1.14.11 ... 

> rucio list-datasets-rse UCSC_LOCALGROUPDISK
SCOPE:NAME
----------

>>> from rucio.client import Client
>>> c = Client()
>>> c.get_dataset_locks_by_rse('UCSC_LOCALGROUPDISK')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/rucio-clients/1.14.11/lib/python2.7/site-packages/rucio/client/lockclient.py", line 70, in get_dataset_locks_by_rse
    status_code=result.status_code)
  File "/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/rucio-clients/1.14.11/lib/python2.7/site-packages/rucio/client/baseclient.py", line 212, in _get_exception
    data = parse_response(data)
  File "/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/rucio-clients/1.14.11/lib/python2.7/site-packages/rucio/common/utils.py", line 215, in parse_response
    return json.loads(data, object_hook=datetime_parser)
  File "/usr/lib64/python2.6/json/__init__.py", line 318, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
```


Discussion:

Resolving patch:
diff --git a/lib/rucio/web/rest/flaskapi/v1/lock.py b/lib/rucio/web/rest/flaskapi/v1/lock.py
--- a/lib/rucio/web/rest/flaskapi/v1/lock.py
+++ b/lib/rucio/web/rest/flaskapi/v1/lock.py
@@ -24,7 +24,7 @@
 from flask.views import MethodView
 
 from rucio.api.lock import get_dataset_locks_by_rse, get_dataset_locks
-from rucio.common.exception import RucioException
+from rucio.common.exception import RucioException, RSENotFound
 from rucio.common.utils import generate_http_error_flask, render_json
 from rucio.web.rest.flaskapi.v1.common import before_request, after_request
 
@@ -58,6 +58,8 @@ def get(self, rse):
                 return Response(data, content_type="application/x-json-stream")
             else:
                 return 'Wrong did_type specified', 500
+        except RSENotFound as error:
+            return generate_http_error_flask(404, error.__class__.__name__, error.args[0])
         except RucioException, error:
             return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
         except Exception, error:
diff --git a/lib/rucio/web/rest/webpy/v1/lock.py b/lib/rucio/web/rest/webpy/v1/lock.py
--- a/lib/rucio/web/rest/webpy/v1/lock.py
+++ b/lib/rucio/web/rest/webpy/v1/lock.py
@@ -23,7 +23,7 @@
 from web import application, ctx, header, InternalError, loadhook
 
 from rucio.api.lock import get_dataset_locks_by_rse, get_dataset_locks
-from rucio.common.exception import RucioException
+from rucio.common.exception import RucioException, RSENotFound
 from rucio.common.schema import SCOPE_NAME_REGEXP
 from rucio.common.utils import generate_http_error, render_json
 from rucio.web.rest.common import rucio_loadhook
@@ -64,6 +64,8 @@ def GET(self, rse):
                     yield render_json(**lock) + '\n'
             else:
                 raise InternalError('Wrong did_type specified')
+        except RSENotFound as error:
+            raise generate_http_error(404, error.__class__.__name__, error.args[0])
         except RucioException as error:
             raise generate_http_error(500, error.__class__.__name__, error.args[0])
         except Exception as error:


Test patch: