diff options
author | ramishra <ramishra@redhat.com> | 2021-04-23 08:36:37 +0530 |
---|---|---|
committer | Brendan Shephard <bshephar@redhat.com> | 2021-04-27 07:06:31 +0000 |
commit | b9a3395978bf60d3ce769b8fcedc60b7127f404f (patch) | |
tree | 327eb1942bfa1eefb7eece744d48e9898de94222 | |
parent | 3a25fe770b29bc8a597992c140e43f5980108127 (diff) | |
download | heat-b9a3395978bf60d3ce769b8fcedc60b7127f404f.tar.gz |
Also, we should not modify a list when iterating
over it.
Task: 42359
Closes-Bug: #1925373
Change-Id: Iaa2c05b4155d93f44de60b6f98a69450c1512817
(cherry picked from commit a8f8528d1ea1952cf76bd09fd27cbd65a978af65)
-rw-r--r-- | heat/engine/hot/functions.py | 14 | ||||
-rw-r--r-- | heat/tests/test_hot.py | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index cf4eaa0f5..2575264c9 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -1603,12 +1603,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)] - - return ret_list + if not self._unique: + 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 753123921..702ca1a1f 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -2367,7 +2367,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) |