Skip to content
Snippets Groups Projects

model.py: format substitutions errors

Merged Axel Prel requested to merge topic/17.0/RED-349 into branch/17.0
All threads resolved!
1 file
+ 21
2
Compare changes
  • Side-by-side
  • Inline
+ 21
2
@@ -19,7 +19,8 @@
##############################################################################
import logging
import traceback
from collections import OrderedDict
from collections.abc import Iterable, Mapping
from typing import Any
@@ -22,8 +23,9 @@
from collections import OrderedDict
from collections.abc import Iterable, Mapping
from typing import Any
from odoo import api, models
from odoo import _, api, models
from odoo.exceptions import UserError
from .base import (
ContextBuilder,
@@ -78,4 +80,5 @@
if self._type:
message_data["__type__"] = self._type
errors = []
for key in self._converters:
@@ -81,4 +84,10 @@
for key in self._converters:
value = self._converters[key].odoo_to_message(instance, ctx)
try:
value = self._converters[key].odoo_to_message(instance, ctx)
except Exception as e:
errors.append(
{"key": key, "traceback": "".join(traceback.format_exception(e))}
)
continue
if value is not Skip:
message_data[key] = value
@@ -83,5 +92,15 @@
if value is not Skip:
message_data[key] = value
if len(errors) != 0:
formatted_errors = "\n\n".join(
[f"{error['traceback']}Key: {error['key']}" for error in errors]
)
raise UserError(
_(
"Got unexpected errors while parsing substitutions:\n"
f"{formatted_errors}"
)
)
if self.merge_with:
for conv in self.merge_with:
Loading