diff --git a/.oca/oca-port/blacklist/base_rest.json b/.oca/oca-port/blacklist/base_rest.json new file mode 100644 index 000000000..89f030759 --- /dev/null +++ b/.oca/oca-port/blacklist/base_rest.json @@ -0,0 +1,5 @@ +{ + "pull_requests": { + "https://github.com/OCA/rest-framework/pull/336": "Nothing to port from PR #https://github.com/OCA/rest-framework/pull/336" + } +} diff --git a/base_rest/components/service.py b/base_rest/components/service.py index b8611bcf2..57a78aea7 100644 --- a/base_rest/components/service.py +++ b/base_rest/components/service.py @@ -3,6 +3,7 @@ import logging +import os from werkzeug.exceptions import NotFound @@ -17,6 +18,23 @@ _logger = logging.getLogger(__name__) +# Disable logging for deprecation. +# You might have big projects, with tons of services with no specific decorator, +# that are well tested and very stable and you don't want to touch them. +# Especially if you plan already to move to v16. +# Since this logging can bloat your CI and your log collecting tools, +# here is a way to prevent that and get only a msg at boot. +DISABLE_DEPRECATE_LOG_KEY = "REST_API_METHOD_FIX_DECORATOR_DEPRECATE_LOG_DISABLE" +DISABLE_DEPRECATE_LOG = os.getenv(DISABLE_DEPRECATE_LOG_KEY) +if DISABLE_DEPRECATE_LOG: + msg = ( + "%s enabled: " + "implicit service methods are deprecated. " + "Disable this env key and enable debug level to have more details." + ) + _logger.warning(msg, DISABLE_DEPRECATE_LOG_KEY) + + def to_int(val): # The javascript VM ducktape only use float and so pass float # to the api, the werkzeug request interpret params as unicode @@ -127,15 +145,16 @@ def _prepare_response(self, method, result): return result routing = getattr(method, ROUTING_DECORATOR_ATTR, None) output_param = routing["output_param"] - if not output_param: + if output_param: + return output_param.to_response(self, result) + elif not output_param and not DISABLE_DEPRECATE_LOG: _logger.warning( "DEPRECATED: You must define an output schema for method %s " "in service %s", method_name, self._name, ) - return result - return output_param.to_response(self, result) + return result def dispatch(self, method_name, *args, params=None): """