[FIX] service: prevent traceback when field value is none

When the value of fields is getting None. And no value is assigned to the
`field`. So the traceback will be generated.

In this commit, we will assign a default value to the field if the field gets a
None value. So that it won't get a None value in any case.

sentry-4211843089

closes odoo/odoo#123193

X-original-commit: 3e652808305d3ef4674963195f3c7cdf91b37654
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
Signed-off-by: Archana Vaghasiya (arva) <arva@odoo.com>
This commit is contained in:
Archana Vaghasiya
2023-06-01 07:01:57 +02:00
parent 837c20371b
commit e10111594e
+3 -4
View File
@@ -72,14 +72,13 @@ def _as_validation_error(env, exc):
""" Return the IntegrityError encapsuled in a nice ValidationError """
unknown = _('Unknown')
model = DotDict({'_name': unknown.lower(), '_description': unknown})
field = DotDict({'name': unknown.lower(), 'string': unknown})
for _name, rclass in env.registry.items():
if exc.diag.table_name == rclass._table:
model = rclass
field = model._fields.get(exc.diag.column_name)
field = model._fields.get(exc.diag.column_name) or field
break
else:
model = DotDict({'_name': unknown.lower(), '_description': unknown})
field = DotDict({'name': unknown.lower(), 'string': unknown})
if exc.pgcode == errorcodes.NOT_NULL_VIOLATION:
return ValidationError(_(