mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-04 15:34:01 -07:00
avoid persistent containers in attribute defaults
moved from the field attribute declaration and created a placeholder which then is resolved in the field attribute class. this is to avoid unwanted persistent of the defaults across objects which introduces stealth bugs when multiple objects of the same kind are used in succession while not overriding the default values.
This commit is contained in:
parent
0719eb3e2d
commit
87969868d4
9 changed files with 29 additions and 18 deletions
|
@ -32,6 +32,17 @@ class Attribute:
|
|||
self.priority = priority
|
||||
self.always_post_validate = always_post_validate
|
||||
|
||||
# This is here to avoid `default=<container>` unwanted persistence across object instances
|
||||
# We cannot rely on None as some fields use it to skip the code
|
||||
# that would detect an empty container as a user error
|
||||
if self.default == '_ansible_container':
|
||||
if self.isa == 'list':
|
||||
self.default = []
|
||||
elif self.isa == 'dict':
|
||||
self.default = {}
|
||||
elif self.isa == 'set':
|
||||
self.default = set()
|
||||
|
||||
def __eq__(self, other):
|
||||
return other.priority == self.priority
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue