inveniosoftware / invenio-records-rest

Invenio records REST API module.
https://invenio-records-rest.readthedocs.io
MIT License
4 stars 62 forks source link

Function return in pass_record should not be inside exception handler. #305

Open Glignos opened 4 years ago

Glignos commented 4 years ago

The return function of this wrapper should be outside the try since the exception handling is solely for the resolving of the PID. Instead the correct way to do it would be:

def inner(self, pid_value, *args, **kwargs):
        try:
            pid, record = request.view_args['pid_value'].data
        except SQLAlchemyError:
            raise PIDResolveRESTError(pid_value)
        return f(self, pid=pid, record=record, *args, **kwargs)
    return inner

After this change is performed the test test_delete_with_sqldatabase_error will start failing since the Exception is not handled then.