Hy!
I've made a REST endpoint similar to the base_rest_demo. i search products and create from odoo product.product object an datamodel object.
this is my datamodel:
`
from marshmallow import fields
from odoo.addons.datamodel.core import Datamodel
#from odoo.addons.datamodel.fields import NestedModel
class SCDatamodelProduct(Datamodel):
_name = "sc.datamodel.product"
id = fields.Integer(required=True, allow_none=False)
name = fields.String(required=True, allow_none=False)
price = fields.Float(required=True, allow_none=False)
taxes_id = fields.Integer(allow_none=True)
tax_included = fields.Boolean(required=True, allow_none=False)
tax_percentage = fields.Float(allow_none=False, default=0.0)
barcode = fields.String(allow_none=True)
internal_reference = fields.String(allow_none=True)
qty_on_hand = fields.Float(allow_none=False, default=0.0)
category = fields.String(allow_none=True)
product_groups = fields.String(allow_none=True)
size_list = fields.String(allow_none=True)
style_list = fields.String(allow_none=True)
weight = fields.String(allow_none=True)`
first time when calling the enpoint, everything works correctly. but at all following calls i get an error:
Traceback (most recent call last):\n File \"/Users/js/DEV/odoo14/odoo/odoo/addons/base/models/ir_http.py\", line 237, in _dispatch\n result = request.dispatch()\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 806, in dispatch\n r = self._call_function(**self.params)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 359, in _call_function\n return checked_call(self.db, *args, **kwargs)\n File \"/Users/js/DEV/odoo14/odoo/odoo/service/model.py\", line 94, in wrapper\n return f(dbname, *args, **kwargs)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 347, in checked_call\n result = self.endpoint(*a, **kw)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 912, in __call__\n return self.method(*args, **kw)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 531, in response_wrap\n response = f(*args, **kw)\n File \"<string>\", line 6, in get_search\n File \"/Users/js/DEV/odoo14/scrimo/dieroester/scrimo_dieroester_api/controllers/controllers.py\", line 23, in _process_method\n response = super(ScrimoRoesterApiServices, self)._process_method(service_name, method_name, *args, params=params)\n File \"/Users/js/DEV/odoo14/oca/rest-framework/base_rest/controllers/main.py\", line 142, in _process_method\n result = service.dispatch(method_name, *args, params=params)\n File \"/Users/js/DEV/odoo14/oca/rest-framework/base_rest/components/service.py\", line 160, in dispatch\n res = method(*args, secure_params)\n File \"/Users/js/DEV/odoo14/oca/rest-framework/base_rest/restapi.py\", line 61, in response_wrap\n response = f(*args, **kw)\n File \"/Users/js/DEV/odoo14/scrimo/dieroester/scrimo_dieroester_api/services/sc_product_service.py\", line 46, in search\n res.append(self._get_product_datamodel(p))\n File \"/Users/js/DEV/odoo14/scrimo/dieroester/scrimo_dieroester_api/services/sc_product_service.py\", line 55, in _get_product_datamodel\n product_datamodel = ProductDatamodel(partial=True)\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow_objects/models.py\", line 81, in __call__\n obj = cls.load(kwargs, many=many, context=context, partial=partial, unknown=unknown,)\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow_objects/models.py\", line 229, in load\n loaded = schema.load(data, many=many)\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow/schema.py\", line 728, in load\n data, many=many, partial=partial, unknown=unknown, postprocess=True\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow/schema.py\", line 902, in _do_load\n partial=partial,\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow/schema.py\", line 1101, in _invoke_load_processors\n partial=partial,\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow/schema.py\", line 1227, in _invoke_processors\n data = processor(data, many=many, **kwargs)\n File \"/Users/js/DEV/odoo14/oca/rest-framework/datamodel/core.py\", line 97, in __make_object__\n return datamodel(__post_load__=True, __schema__=self, **data)\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow_objects/models.py\", line 75, in __call__\n obj.__init__(*args, **kwargs)\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/functools.py\", line 363, in _method\n return self.func(*call_args, **call_keywords)\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/functools.py\", line 363, in _method\n return self.func(*call_args, **call_keywords)\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/functools.py\", line 363, in _method\n return self.func(*call_args, **call_keywords)\n [Previous line repeated 933 more times]\n File \"/Users/js/DEV/odoo14/oca/rest-framework/datamodel/core.py\", line 193, in __init__\n self._env = env\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow_objects/models.py\", line 142, in __setattr__\n self.__setattr_func__(key, value)\n File \"/Users/js/DEV/odoo14/odoo14venv/lib/python3.7/site-packages/marshmallow_objects/models.py\", line 151, in __getattribute__\n if object.__getattribute__(self, \"__dump_mode__\"):\nException\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/Users/js/DEV/odoo14/oca/rest-framework/base_rest/http.py\", line 182, in _handle_exception\n return super(HttpRestRequest, self)._handle_exception(exception)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 744, in _handle_exception\n return super(HttpRequest, self)._handle_exception(exception)\n File \"/Users/js/DEV/odoo14/odoo/odoo/http.py\", line 315, in _handle_exception\n raise exception.with_traceback(None) from new_cause\nRecursionError: maximum recursion depth exceeded while calling a Python object\n",
The REST Endpoint is defined as followed:
@restapi.method(
[(["/", "/search"], "GET")],
input_param=Datamodel("sc.datamodel.product.search"),
output_param=Datamodel("sc.datamodel.product", is_list=True),
auth="api_key"
)
def search(self, product_search_param):
"""
Search for products with name or id. No parameters returns all products.
"""
domain = [('sc_is_webshop_product', '=', True)]
if product_search_param.name:
domain.append(("name", "like", product_search_param.name))
if product_search_param.id:
domain.append(("id", "=", product_search_param.id))
res = []
for p in self.env["product.product"].search(domain):
# res.append(self._get_product_data(p))
res.append(self._get_product_datamodel(p))
return res
def _get_product_datamodel(self, product_odoo):
ProductDatamodel = self.env.datamodels["sc.datamodel.product"]
product_datamodel = ProductDatamodel(partial=True)
if product_odoo:
product_datamodel.id = product_odoo.id
product_datamodel.name = product_odoo.sc_webshop_name if product_odoo.sc_webshop_name else product_odoo.name or ''
product_datamodel.price = product_odoo.list_price
product_datamodel.tax_included = product_odoo.sc_tax_included
if product_odoo.taxes_id and len(product_odoo.taxes_id) > 0:
product_datamodel.taxes_id = product_odoo.taxes_id.id
product_datamodel.tax_percentage = product_odoo.taxes_id[0].amount
product_datamodel.barcode = product_odoo.barcode or ''
product_datamodel.internal_reference = product_odoo.default_code or ''
product_datamodel.qty_on_hand = product_odoo.qty_available or 0.0
#because of email from wolfgang winkler, that categories are set in webshop
#product_datamodel.category = product_odoo.categ_id.display_name if product_odoo.categ_id else None
product_datamodel.product_groups = product_odoo.sc_webshop_product_groups or ''
product_datamodel.size_list = product_odoo.sc_webshop_size_list or ''
product_datamodel.style_list = product_odoo.sc_webshop_style_list or ''
product_datamodel.weight = product_odoo.weight_uom_name or ''
return product_datamodel
product_datamodel = ProductDatamodel(partial=True) this line produces the error.
i searched nearly everything but can't find the solution. the product_datamodel has no nested other models...
any hint how to handle such an error?