fix: we can redefine type of a types child

This commit is contained in:
egarette@silique.fr 2026-06-16 08:06:20 +02:00
parent 7dfdf5376b
commit 1c5dd865b9
10 changed files with 76 additions and 3 deletions

View file

@ -286,7 +286,7 @@ class CollectType:
raise DictConsistencyError(msg, 43, self.sources) raise DictConsistencyError(msg, 43, self.sources)
break break
def set_custom_type(self, custom: dict) -> None: def set_custom_type(self, custom: dict, from_parent: bool=False) -> None:
if self.raises and self.test_exists and self.path in self.objectspace.paths: if self.raises and self.test_exists and self.path in self.objectspace.paths:
msg = f'cannot redefine "{self.path}" object to a custom type' msg = f'cannot redefine "{self.path}" object to a custom type'
raise DictConsistencyError(msg, 64, self.sources) raise DictConsistencyError(msg, 64, self.sources)
@ -298,7 +298,7 @@ class CollectType:
self.user_type = self.types.user_type self.user_type = self.types.user_type
self.sources = self.types.sources + self.sources self.sources = self.types.sources + self.sources
self.object = self.types.object self.object = self.types.object
if self.option_type == "variable" and "type" in self.parameters: if not from_parent and self.option_type == "variable" and "type" in self.parameters:
self.parameters.pop("type") self.parameters.pop("type")
def set_object_user_type_family(self): def set_object_user_type_family(self):
@ -461,7 +461,7 @@ class Collect(CollectType, CollectFamily, CollectVariable):
self.user_type = None self.user_type = None
self.option_type = None self.option_type = None
if parent_option is not None and parent_option.types is not None and self.name in parent_option.types.children: if parent_option is not None and parent_option.types is not None and self.name in parent_option.types.children:
self.set_custom_type(parent_option.types.children[self.name]) self.set_custom_type(parent_option.types.children[self.name], from_parent=True)
self.check_no_extra_keys = False self.check_no_extra_keys = False
if self.test_exists and path in objectspace.paths: if self.test_exists and path in objectspace.paths:
for source in reversed(self.objectspace.paths[path].xmlfiles): for source in reversed(self.objectspace.paths[path].xmlfiles):

View file

@ -173,3 +173,11 @@ def test_type_family_secret():
def test_type_family_secret_namespace(): def test_type_family_secret_namespace():
type_variable("family_secret_manager", namespace=True) type_variable("family_secret_manager", namespace=True)
def test_type_family_redefine_type():
type_variable("family_redefine_type")
def test_type_family_redefine_type_namespace():
type_variable("family_redefine_type", namespace=True)

View file

@ -0,0 +1,14 @@
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
from re import compile as re_compile
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
try:
groups.namespace
except:
groups.addgroup('namespace')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_2 = PasswordOption(name="my_type", doc="My type", default="a value", properties=frozenset({"mandatory", "one_tag", "standard"}), informations={'ymlfiles': ['tests/types/types/family_redefine_type/00_type.yml', 'tests/types/structures/family_redefine_type/00_structure.yml'], 'type': 'secret', 'tags': ('one_tag',)})
optiondescription_1 = OptionDescription(name="my_family", doc="My family type", children=[option_2], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_redefine_type/00_type.yml', 'tests/types/structures/family_redefine_type/00_structure.yml']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,3 @@
{
"my_family.my_type": "a value"
}

View file

@ -0,0 +1,3 @@
{
"my_family.my_type": "a value"
}

View file

@ -0,0 +1,15 @@
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
from re import compile as re_compile
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
try:
groups.namespace
except:
groups.addgroup('namespace')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_4 = PasswordOption(name="my_type", doc="My type", default="a value", properties=frozenset({"mandatory", "one_tag", "standard"}), informations={'ymlfiles': ['tests/types/types/family_redefine_type/00_type.yml', 'tests/types/structures/family_redefine_type/00_structure.yml'], 'type': 'secret', 'tags': ('one_tag',)})
optiondescription_3 = OptionDescription(name="my_family", doc="My family type", children=[option_4], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_redefine_type/00_type.yml', 'tests/types/structures/family_redefine_type/00_structure.yml']})
optiondescription_2 = OptionDescription(name="ns2", doc="NS2", group_type=groups.namespace, children=[optiondescription_3], properties=frozenset({"standard"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_2])

View file

@ -0,0 +1,3 @@
{
"ns2.my_family.my_type": "a value"
}

View file

@ -0,0 +1,3 @@
{
"ns2.my_family.my_type": "a value"
}

View file

@ -0,0 +1,11 @@
%YAML 1.2
---
version: 1.1
my_family:
type: my_family_type
my_type:
redefine: true
type: secret
...

View file

@ -0,0 +1,13 @@
%YAML 1.2
---
version: 1.1
my_family_type:
description: My family type
my_type:
description: My type
default: a value
tags:
- one_tag
...