[FIX] base: browse(record) in company-dependent field value
The faulty code modifies a dictionary in-place to apply a formatting
function to each value. In this case, the formatting is `browse`, and
the issue occurs when `ids` contain duplicates:
for id in ids:
result[id] = format(result.get(id, default))
Fix it by returning a new dictionary based on `result`.
X-original-commit: bd4565e227c7196604af9c5c51ce136a2beac088
This commit is contained in:
@@ -302,11 +302,12 @@ class Property(models.Model):
|
||||
cr.execute(query, params + [sub_refs])
|
||||
result.update(cr.fetchall())
|
||||
|
||||
# remove default value, add missing values, and format them
|
||||
default = result.pop(None, None)
|
||||
for id in ids:
|
||||
result[id] = clean(result.get(id, default))
|
||||
return result
|
||||
# determine all values and format them
|
||||
default = result.get(None, None)
|
||||
return {
|
||||
id: clean(result.get(id, default))
|
||||
for id in ids
|
||||
}
|
||||
|
||||
@api.model
|
||||
def set_multi(self, name, model, values, default_value=None):
|
||||
|
||||
@@ -998,6 +998,12 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
self.assertEqual(record.with_user(user1).tag_id, tag2)
|
||||
self.assertEqual(record.with_user(user2).tag_id, tag0)
|
||||
|
||||
# regression: duplicated records caused values to be browse(browse(id))
|
||||
recs = record.create({}) + record + record
|
||||
recs.invalidate_cache()
|
||||
for rec in recs.with_user(user0):
|
||||
self.assertIsInstance(rec.tag_id.id, int)
|
||||
|
||||
# unlink value of a many2one (tag2), and check again
|
||||
tag2.unlink()
|
||||
self.assertEqual(record.with_user(user0).tag_id, tag1)
|
||||
|
||||
Reference in New Issue
Block a user