From c494a4662fdd215adf76d3a915de5edc183a5a5b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 9 Apr 2025 09:02:32 +0200 Subject: [PATCH] fix: better detection of multi variable in default attribute --- src/rougail/object_model.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/rougail/object_model.py b/src/rougail/object_model.py index 9eee28439..7a39a7b02 100644 --- a/src/rougail/object_model.py +++ b/src/rougail/object_model.py @@ -507,12 +507,15 @@ class _VariableCalculation(Calculation): if self.allow_none: params["allow_none"] = True if needs_multi is None: - if self.attribute_name != "default": - needs_multi = True + if self.attribute_name == "default": + # variable is a multi or a submulti follower + attended = "submulti" if self.path in objectspace.followers else True + needs_multi = objectspace.multis.get(self.path) == attended else: - needs_multi = self.path in objectspace.multis + needs_multi = True calc_variable_is_multi = variable.path in objectspace.multis if not calc_variable_is_multi: + # a variable in a dynamic family can be multiple if variable.path in objectspace.paths._dynamics and ( identifier is None or identifier[-1] is None ): @@ -538,10 +541,9 @@ class _VariableCalculation(Calculation): elif self.inside_list: msg = _('the variable "{0}" has an invalid attribute "{1}", it\'s a list').format(self.path, self.attribute_name) raise DictConsistencyError(msg, 23, self.xmlfiles) - elif calc_variable_is_multi: + elif calc_variable_is_multi and self.path in objectspace.followers: if ( - variable.multi - or variable.path.rsplit(".", 1)[0] != self.path.rsplit(".", 1)[0] + variable.path.rsplit(".", 1)[0] != self.path.rsplit(".", 1)[0] ): if is_variable_calculation: # it's not a follower or not in same leadership @@ -576,7 +578,7 @@ class VariableCalculation(_VariableCalculation): or (objectspace.force_optional and self.attribute_name == "default") ): raise VariableCalculationDependencyError() - if self.attribute_name == "default": + if variable and self.attribute_name == "default": local_variable = objectspace.paths[self.path] if CONVERT_OPTION.get(local_variable.type, {}).get("func", str) != CONVERT_OPTION.get(variable.type, {}).get("func", str): msg = _('variable "{0}" has a default value calculated with "{1}" which has incompatible type').format(self.path, variable.path)