[FIX] finally make pytest work properly w/ model proxy

At some point pytest added support for dataclass & attrs introspection
by looking up some specific meta-fields when trying to format
objects (after an assertion fails).

It tries to access the attributes, falls back to something else if it
gets an AttributeError but apparently falls over if it gets something
else, which is what'd happen here as read() would generate a
ValueError which would get re-raised as-is on the client
side.. However pytest doesn't really make the issue clear, and the
logging from RPC likely got lost in the noise from the github logging.

The fix is to simply convert errors from read() into proper
AttributeError. And blacklist fields we know make no sense to avoid
confusing tracebacks in the log.
This commit is contained in:
Xavier Morel 2020-01-27 14:10:58 +01:00
parent 43e6f5e5ec
commit 0d33b87579

View File

@ -996,6 +996,8 @@ class Model:
return Model(self._env, self._model, ids, fields=self._fields)
def __getattr__(self, fieldname):
if fieldname in ['__dataclass_fields__', '__attrs_attrs__']:
raise AttributeError('%r is invalid on %s' % (fieldname, self._model))
if not self._ids:
return False
@ -1003,7 +1005,10 @@ class Model:
if fieldname == 'id':
return self._ids[0]
val = self.read([fieldname])[0][fieldname]
try:
val = self.read([fieldname])[0][fieldname]
except Exception:
raise AttributeError('%r is invalid on %s' % (fieldname, self._model))
field_description = self._fields[fieldname]
if field_description['type'] in ('many2one', 'one2many', 'many2many'):
val = val or []