From a2acf91958eca7a5abcdbe22d0da482b731fcc6f Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 7 Apr 2023 14:58:43 +0000 Subject: [PATCH] [IMP] core: models `__repr__` should show when ids is wrong As a developer, when you craft your records set manually, and wrongly use the API and set something weird in `ids`, something else than a tuple of integers, `repr` should help you to understand you did something wrong. e.g. before ```py In [1]: env['res.partner']._browse(self.env, '(1,)', 'bar') Out[1]: res.partner(1,) ``` after ```py In [1]: env['res.partner']._browse(self.env, '(1,)', 'bar') Out[1]: res.partner'(1,)' ``` We could put an assert in `_browse` to make sure `ids` is a tuple of integers, but this is considered a non-stable change, as it will suddenly crashes when you will update Odoo while it wasn't the case before. closes odoo/odoo#118119 X-original-commit: f689c4f53fc4663b17c57bd1d704b9ffb9f11f8d Signed-off-by: Denis Ledoux (dle) --- odoo/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odoo/models.py b/odoo/models.py index df3e7649116..b1c92c631f4 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -5914,7 +5914,7 @@ class BaseModel(metaclass=MetaModel): return self.id or 0 def __repr__(self): - return f"{self._name}{self._ids}" + return f"{self._name}{self._ids!r}" def __hash__(self): return hash((self._name, frozenset(self._ids)))