major
minor
major
minor
minor
#26461
Overridden attribute inherits mandatory "Default value" customization
A Class A defines a string attribute "s" and annotates it with a default value "v." This means that when an instance of A is created, the attribute "s" is assigned the value "v."
Class B inherits from A, overrides the "s" attribute, and **instead** of the default value, annotates a storage rule that calculates the value of "s".
This works perfectly at first.
However, if this model configuration is exported and then reimported, or if an empty database is initialized with it, the overridden attribute "s" in class B always receives both: the default value (inherited from A) and the storage rule (annotated on B).
As a result, the creation of instances of class B fails because the default value for calculated attributes cannot be saved.
You can resolve this issue within the app by removing the “Default Value” annotation from the overridden attribute in the Model Editor.
However, this change is not reflected in the export or is lost upon reimport.
Analysis
Currently, when a new overridden attribute is created, all annotations are implicitly copied. This occurs regardless of whether the attribute is created via the GUI or imported via XML. Therefore, deleting such an implicitly created annotation in the application has no effect on the export and re-import.
Improvement
Annotations are no longer copied when overridden attributes are created. Instead, when looking up annotations, an additional fallback mechanism is implemented that uses an annotation on the overridden attribute as a fallback before the corresponding annotation in the attribute type is used. However, for each annotation type, this behavior can be controlled via the @AnnotationInheritance meta-annotation using the policies `inherit`, `redefine`, or `final`. The previous @CanNotOverride meta-annotation is deprecated and replaced by the `final` annotation inheritance policy.
Code Migration
- If the application defines an overridden attribute that is intended to inherit the default value unchanged from its original attribute, this default value must be repeated for the overridden attribute in the model definition. When exporting the model from a running application with data from before the change, this migration occurs automatically.
Test
- /com.top_logic.demo/src/test/java/test/com/top_logic/demo/scripted/model/attribute/defaultValue/TestOverridingDefaultWithDerived.script.xml
Manual:
- Import the attached configuration.
- No instances of type B can be created (Instance tab).
- In the model editor, delete the "Default Value" annotation from the B::constantValue attribute.
- After that, creating instances of type B will work.
- Now export the module.
- Delete all created instances and the module.
- Re-import the previously exported module.
-> Expectation: No change; creating Bs still works.
-> Actual: The "default value" annotation on B::constantValue has been regenerated. No Bs can be created.