From a8f8528d1ea1952cf76bd09fd27cbd65a978af65 Mon Sep 17 00:00:00 2001 From: ramishra Date: Fri, 23 Apr 2021 08:36:37 +0530 Subject: [PATCH] Preserve order in list_concat_unique Also, we should not modify a list when iterating over it. Task: 42359 Closes-Bug: #1925373 Change-Id: Iaa2c05b4155d93f44de60b6f98a69450c1512817 --- heat/engine/hot/functions.py | 12 +++++++----- heat/tests/test_hot.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index 33b75f4e4d..a309392b31 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -1643,12 +1643,14 @@ class ListConcat(function.Function): for m in args: ret_list.extend(ensure_list(m)) - if self._unique: - for i in ret_list: - while ret_list.count(i) > 1: - del ret_list[ret_list.index(i)] + if not self._unique: + return ret_list - return ret_list + unique_list = [] + for item in ret_list: + if item not in unique_list: + unique_list.append(item) + return unique_list class ListConcatUnique(ListConcat): diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index a0ec62ae82..a4f4c3d32a 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -2399,7 +2399,7 @@ resources: self.assertEqual(snippet_resolved, resolved) def test_list_concat_unique(self): - snippet = {'list_concat_unique': [['v1', 'v2'], ['v2', 'v3']]} + snippet = {'list_concat_unique': [['v1', 'v2'], ['v1', 'v3']]} snippet_resolved = ['v1', 'v2', 'v3'] tmpl = template.Template(hot_pike_tpl_empty) resolved = self.resolve(snippet, tmpl)