Skip to content
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

[FIX] base: traceback on rpc call if data contain default dict #129830

Closed
wants to merge 1 commit into from

Conversation

niyasraphy
Copy link
Contributor

before this commit, on reading data with default dict data type is showing error to end user, without returning the requested data.

for eg, if a read operation is triggered on model sale.order it wont return the requested data, instead traceback is shown in response.

in sale.order model the tax_totals field is a computed field, with data as format default dict which was
causing the issue.

after this commit, without any traceback the requested data will be returned to the user.

Issue: #129183
Issue: #129494


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Jul 26, 2023

@C3POdoo C3POdoo requested review from a team, VincentSchippefilt and Julien00859 and removed request for a team July 26, 2023 17:27
@Julien00859
Copy link
Member

Hello @niyasraphy nice catch, thanks for the fix!

Can you add the following test please?

diff --git a/odoo/addons/base/tests/test_xmlrpc.py b/odoo/addons/base/tests/test_xmlrpc.py
index ed47d691e6dd..978f6167cab2 100644
--- a/odoo/addons/base/tests/test_xmlrpc.py
+++ b/odoo/addons/base/tests/test_xmlrpc.py
@@ -1,11 +1,13 @@
 # -*- coding: utf-8 -*-
 # Part of Odoo. See LICENSE file for full copyright and licensing details.
+import collections
 import time
 from xmlrpc.client import Binary
 
 from odoo.exceptions import AccessDenied, AccessError
 from odoo.http import _request_stack
 
+import odoo
 import odoo.tools
 from odoo.tests import common
 from odoo.service import common as auth, model
@@ -72,6 +74,15 @@ class TestXMLRPC(common.HttpCase):
         self.assertEqual(ctx['lang'], 'en_US')
         self.assertEqual(ctx['tz'], 'Europe/Brussels')
 
+    def test_xmlrpc_defaultdict_marshalling(self):
+        """
+        Test that the marshalling of a collections.defaultdict object
+        works properly over XMLRPC
+        """
+        self.patch(self.registry['res.users'], 'context_get',
+            odoo.api.model(lambda *_: collections.defaultdict(int)))
+        self.assertEqual(self.xmlrpc('res.users', 'context_get'), {})
+
     def test_jsonrpc_read_group(self):
         self._json_call(
             common.get_db_name(), self.admin_uid, 'admin',

before this commit, on reading data with default dict data
type is showing error to end user, without returning the
requested data.

for eg, if a read operation is triggered on model sale.order
it wont return the requested data, instead traceback is
shown in response.

in sale.order model the tax_totals field is a computed
field, with data as format default dict which was
causing the issue.

after this commit, without any traceback the requested
data will be returned to the user.
@niyasraphy
Copy link
Contributor Author

hi @Julien00859 ,
thanks for the review and test case.
updated the PR

Copy link
Member

@Julien00859 Julien00859 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants