[FIX] core: make accessing fields from __str__ possible
Because CacheMiss calls str() on the record it's given, it's not possible to override __str__ and get field values: on the first cache miss (= the first field access) we're going to blow the stack: * any random field is accessed * and faults * which creates a CacheMiss * which stringifies the record * which accesses a field * which faults * which creates a CacheMiss * etc... Fix: * move the basic Model's stringification to repr(), which is implicitly called on str() if no __str__ is specified, for historical reasons we were doing the opposite * use repr() when initialising CacheMiss closes odoo/odoo#42966 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
+1
-1
@@ -104,7 +104,7 @@ class CacheMiss(except_orm, KeyError):
|
||||
"""
|
||||
|
||||
def __init__(self, record, field):
|
||||
super(CacheMiss, self).__init__("%s.%s" % (str(record), field.name))
|
||||
super(CacheMiss, self).__init__("%r.%s" % (record, field.name))
|
||||
|
||||
|
||||
class MissingError(except_orm):
|
||||
|
||||
+1
-3
@@ -5665,10 +5665,8 @@ Record ids: %(records)s
|
||||
def __int__(self):
|
||||
return self.id or 0
|
||||
|
||||
def __str__(self):
|
||||
return "%s%s" % (self._name, getattr(self, '_ids', ""))
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
return "%s%s" % (self._name, getattr(self, '_ids', ""))
|
||||
|
||||
def __hash__(self):
|
||||
if hasattr(self, '_ids'):
|
||||
|
||||
Reference in New Issue
Block a user