Commit 0eb1c880 by James Cammarata

Use itertools instead of set for tags, as the data may not hash well

The tags field may contain bad data before it is post_validated, however
some methods assumed it would be a simple list or string. Using itertools
gets us around the problem of the data potentially not being hashable

Fixes #9380
parent af49944a
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import itertools
import uuid import uuid
from functools import partial from functools import partial
...@@ -232,6 +233,10 @@ class Base: ...@@ -232,6 +233,10 @@ class Base:
new_me._loader = self._loader new_me._loader = self._loader
new_me._variable_manager = self._variable_manager new_me._variable_manager = self._variable_manager
# if the ds value was set on the object, copy it to the new copy too
if hasattr(self, '_ds'):
new_me._ds = self._ds
return new_me return new_me
def post_validate(self, templar): def post_validate(self, templar):
...@@ -340,7 +345,8 @@ class Base: ...@@ -340,7 +345,8 @@ class Base:
if not isinstance(new_value, list): if not isinstance(new_value, list):
new_value = [ new_value ] new_value = [ new_value ]
return list(set(value + new_value)) #return list(set(value + new_value))
return [i for i,_ in itertools.groupby(value + new_value)]
def __getstate__(self): def __getstate__(self):
return self.serialize() return self.serialize()
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import itertools
from six import string_types from six import string_types
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
...@@ -67,7 +68,7 @@ class Taggable: ...@@ -67,7 +68,7 @@ class Taggable:
else: else:
tags = set([tags]) tags = set([tags])
else: else:
tags = set(tags) tags = [i for i,_ in itertools.groupby(tags)]
else: else:
# this makes intersection work for untagged # this makes intersection work for untagged
tags = self.__class__.untagged tags = self.__class__.untagged
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment