mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Do not use mutable defaults in FieldAttribute, instead allow supplying a callable for defaults of mutable types. Fixes #46824 (#46833)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
---
|
||||
- hosts: testhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Static imports should expose vars at parse time, not at execution time
|
||||
assert:
|
||||
that:
|
||||
- static_defaults_var == 'static_defaults'
|
||||
- static_vars_var == 'static_vars'
|
||||
- import_role:
|
||||
name: static
|
||||
- assert:
|
||||
that:
|
||||
- static_tasks_var == 'static_tasks'
|
||||
- static_defaults_var == 'static_defaults'
|
||||
- static_vars_var == 'static_vars'
|
||||
|
||||
- hosts: testhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Ensure vars from import_roles do not bleed between plays
|
||||
assert:
|
||||
that:
|
||||
- static_defaults_var is undefined
|
||||
- static_vars_var is undefined
|
||||
@@ -81,3 +81,4 @@ ANSIBLE_STRATEGY='free' ansible-playbook tasks/test_include_dupe_loop.yml -i ../
|
||||
test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3
|
||||
|
||||
ansible-playbook public_exposure/playbook.yml -i ../../inventory "$@"
|
||||
ansible-playbook public_exposure/no_bleeding.yml -i ../../inventory "$@"
|
||||
|
||||
@@ -347,13 +347,13 @@ class BaseSubClass(base.Base):
|
||||
_test_attr_list = FieldAttribute(isa='list', listof=string_types, always_post_validate=True)
|
||||
_test_attr_list_no_listof = FieldAttribute(isa='list', always_post_validate=True)
|
||||
_test_attr_list_required = FieldAttribute(isa='list', listof=string_types, required=True,
|
||||
default=[], always_post_validate=True)
|
||||
default=list, always_post_validate=True)
|
||||
_test_attr_string = FieldAttribute(isa='string', default='the_test_attr_string_default_value')
|
||||
_test_attr_string_required = FieldAttribute(isa='string', required=True,
|
||||
default='the_test_attr_string_default_value')
|
||||
_test_attr_percent = FieldAttribute(isa='percent', always_post_validate=True)
|
||||
_test_attr_set = FieldAttribute(isa='set', default=set(), always_post_validate=True)
|
||||
_test_attr_dict = FieldAttribute(isa='dict', default={'a_key': 'a_value'}, always_post_validate=True)
|
||||
_test_attr_set = FieldAttribute(isa='set', default=set, always_post_validate=True)
|
||||
_test_attr_dict = FieldAttribute(isa='dict', default=lambda: {'a_key': 'a_value'}, always_post_validate=True)
|
||||
_test_attr_class = FieldAttribute(isa='class', class_type=ExampleSubClass)
|
||||
_test_attr_class_post_validate = FieldAttribute(isa='class', class_type=ExampleSubClass,
|
||||
always_post_validate=True)
|
||||
|
||||
Reference in New Issue
Block a user