Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .oca/oca-port/blacklist/base_rest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
25 changes: 22 additions & 3 deletions base_rest/components/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import logging
import os

from werkzeug.exceptions import NotFound

Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
Loading