Major
Detail
Major
Detail
Detail
#26461
Overridden attribute inherits mandatory "Default value" customization
A class A defines a string attribute "s" and annotates a default value "v" for it. That is, when an instance of A is created, the attribute "s" is assigned the value "v".
A class B inherits from A, overwrites the attribute "s" and now **instead** of the default value annotates a storage rule that computes the value of "s".
This works fine at first.
However, if this model configuration is exported and then reimported or an empty database is initialized with it, the overwritten attribute "s" at class B always receives both: both the default value (inherited from A) and the storage rule (annotated to B).
Thus, the creation of instances of class B fails because the default value for computed attributes cannot be stored.
The problem can be fixed in-app by removing the "default value" annotation on the overridden attribute in the model editor.
However, this change will not be reflected in the export or will be lost during reimport.
Analysis
Currently, when creating a new overwritten attribute, all annotations are implicitly copied. This happens regardless of whether the attribute is created at the GUI or imported via XML. Therefore, deleting such an implicitly created annotation in the application has no effect on export and re-import.
Improvement
Annotations are no longer copied when overridden attributes are created. Instead, when annotations are looked up, another fallback is built in, which takes an annotation on the overwritten attribute as a fallback before the corresponding annotation is used in the attribute type. However, per annotation type this behavior can be controlled via the meta annotation @AnnotationInheritance with the policy inherit, redefine or final. The previous meta annotation @CanNotOverride is dropped and replaced by the annotation inheritance policy final.
Code migration
- If the application defines an overridden attribute that should inherit the default value unchanged from its original attribute, this default value must be repeated on the overridden attribute in the model definition. When exporting the model from a running application with a data state from before the change, this migration causes automatically.
Test
- /com.top_logic.demo/src/test/java/test/com/top_logic/demo/scripted/model/attribute/defaultValue/TestOverridingDefaultWithDerived.script.xml
Manually:
- Import attached configuration.
- No type B instances can be created (instance tab).
- In the model editor delete the annotation "default value" at the attribute B::constantValue.
- After that the creation of instances of type B works.
- Now export the module.
- Delete all created instances and the module.
- Import the previously exported module again.
-> Expectation: No change, creation of Bs still works.
-> Actual: The annotation "default value" at B::constantValue was created again. No Bs can be created.