rest-framework icon indicating copy to clipboard operation
rest-framework copied to clipboard

[IMP] Deprecate old API

Open lmignon opened this issue 3 years ago • 7 comments

At startup, output deprecation message for methods not explicitely declared with the new api decorator

To help adapt the code, the decorator to add to the method not declared with the new api decorator is printed into the log file.

2022-06-15 15:02:07,093 535175 WARNING odoo-14-test odoo.addons.base_rest.models.rest_service_registration: "Deprecated REST API implicit method "session_expired" in service "exception.service"
The support for implicit rest method will be removed in 16.0
You should consider to explicitly declare your method as a rest method by adding the following decorator
@restapi.method(
    [('/session_expired', 'POST')],
    input_param=restapi.CerberusValidator(schema='_validator_session_expired'),
    output_param=restapi.CerberusValidator(schema='_validator_return_session_expired')
)
def session_expired(...):

lmignon avatar Jun 15 '22 15:06 lmignon

ping @simahawk @sbidoul

lmignon avatar Jun 15 '22 15:06 lmignon

@sbidoul @simahawk The deprecation message is logged as warning. This makes runboat build fails. Do I change the level to info?

lmignon avatar Jun 15 '22 15:06 lmignon

That's not the reason for the build failure. I was connected to the template1 db to show something to Pierrick. Please retry.

sbidoul avatar Jun 15 '22 15:06 sbidoul

@simahawk I'm not sure that logging the details at debug level is a good idea. Personally, I only activate the debug level for some specific addons in some specific cases when we encounter unexpected behavior in production. Moreover, developers will never think about activating the debug level to get the details that will help them to adapt their code. If you are annoyed by the warnings, it's easy to fix your code with the details into the log message to get rid of them.

lmignon avatar Jun 16 '22 06:06 lmignon

@simahawk I'm not sure that logging the details at debug level is a good idea. Personally, I only activate the debug level for some specific addons in some specific cases when we encounter unexpected behavior in production. Moreover, developers will never think about activating the debug level to get the details that will help them to adapt their code. If you are annoyed by the warnings, it's easy to fix your code with the details into the log message to get rid of them.

I'm not saying you shouldn't see anything. I'm saying log the deprecation w/out the detail in INFO mode and mention that more details can be seen w/ DEBUG mode. Eg:

""" Deprecated REST API implicit method "session_expired" in service "exception.service". The support for implicit rest method will be removed in 16.0. For full details please enable DEBUG level """ IMO logging the same thing hundreds time won't help devs more.

simahawk avatar Jun 16 '22 07:06 simahawk

@simahawk And once you enable the debug log level the information you're looking for is lost in a tons of useless log entries....

lmignon avatar Jun 16 '22 08:06 lmignon

done

2022-06-16 08:56:30,589 574334 WARNING odoo-14-test odoo.addons.base_rest.models.rest_service_registration: Deprecated REST API implicit method "get" in service "partner_image.service". The support for implicit rest method will be removed in 16.0. For full details on how to adapt your code, please enable DEBUG level 
2022-06-16 08:56:30,590 574334 DEBUG odoo-14-test odoo.addons.base_rest.models.rest_service_registration: Add the following decorator to fix this issue:
@restapi.method(
    [(['/<int:id>/get', '/<int:id>'], 'GET')],
    input_param=restapi.CerberusValidator(schema='_validator_get')
)
def get(...):

lmignon avatar Jun 16 '22 08:06 lmignon

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Oct 16 '22 12:10 github-actions[bot]

@simahawk Can you update your review PLZ? Thank you

lmignon avatar Nov 21 '22 08:11 lmignon

/ocabot merge patch

lmignon avatar Nov 22 '22 15:11 lmignon

This PR looks fantastic, let's merge it! Prepared branch 14.0-ocabot-merge-pr-270-by-lmignon-bump-patch, awaiting test results.

OCA-git-bot avatar Nov 22 '22 15:11 OCA-git-bot

Congratulations, your PR was merged at 90e695559e61186501645e63d09c620abce6f803. Thanks a lot for contributing to OCA. ❤️

OCA-git-bot avatar Nov 22 '22 15:11 OCA-git-bot