-
-
Notifications
You must be signed in to change notification settings - Fork 118
[18.0][FIX] webservice: always return the full response, drop content_only #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| On upgrade from a version prior to `18.0.2.0.1`, a | ||
| `webservice.request_content_only` system parameter is created automatically | ||
| (see that version's migration script) to preserve the previous default | ||
| behavior of HTTP calls, which returned only the response content instead of | ||
| the full `requests.Response` object. | ||
|
|
||
| If your code relies on that implicit default, keep the parameter for now. | ||
| Once it's adapted to use the full response object (see *Usage*), delete the | ||
| parameter under *Settings > Technical > System Parameters* - new installs | ||
| never get it set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from . import test_content_only_compat | ||
| from . import test_oauth2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
| import responses | ||
|
|
||
| from .common import CommonWebService | ||
|
|
||
|
|
||
| class TestContentOnlyCompat(CommonWebService): | ||
| """`content_only` removal, and its backward-compat system parameter. | ||
|
|
||
| This lives in `webservice`, not `webservice_core`: the compat switch | ||
| only matters for databases that already ran with the old | ||
| `content_only=True` default, and that's `webservice`'s history, not | ||
| `webservice_core`'s (a new, not-yet-released module nobody depends on | ||
| with that old default). | ||
| """ | ||
|
|
||
| @classmethod | ||
| def _setup_records(cls): | ||
| res = super()._setup_records() | ||
| cls.url = "https://localhost.demo.odoo/" | ||
| cls.webservice = cls.env["webservice.backend"].create( | ||
| { | ||
| "name": "WebService", | ||
| "protocol": "http", | ||
| "url": cls.url, | ||
| "tech_name": "demo_ws_content_only", | ||
| "auth_type": "none", | ||
| } | ||
| ) | ||
| return res | ||
|
|
||
| @responses.activate | ||
| def test_returns_full_response_by_default(self): | ||
| responses.add(responses.GET, self.url, body="{}") | ||
| result = self.webservice.call("get") | ||
| self.assertEqual(result.content, b"{}") | ||
| self.assertEqual(result.status_code, 200) | ||
|
|
||
| @responses.activate | ||
| def test_compat_param_restores_content_only(self): | ||
| self.env["ir.config_parameter"].sudo().set_param( | ||
| "webservice.request_content_only", "1" | ||
| ) | ||
| responses.add(responses.GET, self.url, body="{}") | ||
| with self.assertLogs( | ||
| "odoo.addons.webservice.models.webservice_backend", level="WARNING" | ||
| ) as log_catcher: | ||
| result = self.webservice.call("get") | ||
| self.assertEqual(result, b"{}") | ||
| self.assertTrue( | ||
| any("webservice.request_content_only" in m for m in log_catcher.output) | ||
| ) | ||
|
|
||
| @responses.activate | ||
| def test_content_only_kwarg_is_ignored(self): | ||
| """The removed `content_only` kwarg no longer has any effect.""" | ||
| responses.add(responses.GET, self.url, body="{}") | ||
| with self.assertLogs( | ||
| "odoo.addons.webservice.models.webservice_backend", level="WARNING" | ||
| ) as log_catcher: | ||
| result = self.webservice.call("get", content_only=True) | ||
| self.assertEqual(result.content, b"{}") | ||
| self.assertTrue(any("content_only" in m for m in log_catcher.output)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| CONTENT_ONLY_COMPAT_PARAM = "webservice.request_content_only" | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| """Preserve the pre-upgrade behavior of HTTP webservice calls. | ||
|
|
||
| Before this version, ``webservice.backend.call()`` (and friends) | ||
| returned only the response content (raw bytes) by default. That default | ||
| is gone: calls now always return the full ``requests.Response`` object. | ||
|
|
||
| Existing databases get ``CONTENT_ONLY_COMPAT_PARAM`` set so their | ||
| calling code keeps working unchanged until it's adapted; new installs | ||
| never get it, so they see the new behavior right away. Leave the | ||
| parameter unset (or delete it) once the calling code is updated. | ||
| """ | ||
| icp = env["ir.config_parameter"].sudo() | ||
| if not icp.search_count([("key", "=", CONTENT_ONLY_COMPAT_PARAM)]): | ||
| icp.set_param(CONTENT_ONLY_COMPAT_PARAM, "1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.