From a735ea7a2b40110f23469043baf8d6972f9afcd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 21 Oct 2025 12:07:40 +0200 Subject: [PATCH] Make target ids unique when reading related fields The result is converted into a dict based on the id so we must ensure that the ids read are unique in case the same id appears after size limit. Closes #14304 --- trytond/trytond/model/modelsql.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 55cfb5038e..f915ad2b3d 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -1317,6 +1317,8 @@ class ModelSQL(ModelStorage): if value is not None: add(value) related_read_limit = transaction.context.get('related_read_limit') + # use dict keys to make target ids unique but preserving the order + target_ids = list(dict.fromkeys(target_ids).keys()) rows = Target.read(target_ids[:related_read_limit], fields) if related_read_limit is not None: rows += [{'id': i} for i in target_ids[related_read_limit:]]