fix: better detection of multi variable in default attribute

This commit is contained in:
egarette@silique.fr 2025-04-09 09:02:32 +02:00
parent 0bc1e24d38
commit c494a4662f

View file

@ -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)