Skip to content

Commit

Permalink
[FIX] base: traceback on rpc call if data contain default dict
Browse files Browse the repository at this point in the history
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.

closes #129830

Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
  • Loading branch information
niyasraphy committed Aug 7, 2023
1 parent 056c724 commit cc61b92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions odoo/addons/base/controllers/rpc.py
Expand Up @@ -4,6 +4,7 @@
import xmlrpc.client
from datetime import date, datetime

from collections import defaultdict
from markupsafe import Markup

import odoo
Expand Down Expand Up @@ -109,6 +110,7 @@ def dump_lazy(self, value, write):
dispatch[date] = dump_date
dispatch[lazy] = dump_lazy
dispatch[Command] = dispatch[int]
dispatch[defaultdict] = dispatch[dict]
dispatch[Markup] = lambda self, value, write: self.dispatch[str](self, str(value), write)


Expand Down
11 changes: 11 additions & 0 deletions 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
Expand Down Expand Up @@ -72,6 +74,15 @@ def test_xmlrpc_frozendict_marshalling(self):
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',
Expand Down

0 comments on commit cc61b92

Please sign in to comment.