Cached value of a Variable referencing an asserted property is not updated when a literal is added
Summary
A Variable that has a value that is defined by a default value from an assertion in the property relation, such as http://www.simantics.org/Diagram-2.2/Element/profileMonitorOffset
, retains its cached value, when the database is updated to include literal value for the property.
This may result in various displays of outdated values, as well as loss of data, when values are updated using repeated calls to updates of field or elements values in literals with structured data types.
What happened & Steps to reproduce
The error can be reproduced by calling the following function on a diagram element that does not have a defined profileMonitorOffset
value:
> setProfileMonitorOffset r x y = do
var = resourceVariable r
v = property var "profileMonitorOffset"
setPropertyValue v "n-x" x
setPropertyValue v "n-y" y
> setProfileMonitorOffset (getElement currentModel "PIP02") 100 100
Expected results & Actual results
The expected result of calling the above function is that the profileMonitorOffset
property has acquired the value { x = 100.0, y = 100.0 }
. Instead, the generated value is { x = 0.0, y = 100.0 }
.
When the same function is called for an element that already has a defined property value, both the x and y fields of the value are properly updated.
Workaround & How to fix this
This problem can be mitigated by requesting a new @Variable@ instance between the calls to subliteral value udpates:
setProfileMonitorOffset r x y = do
var = resourceVariable r
v = property var "profileMonitorOffset"
setPropertyValue v "n-x" x
v2 = property var "profileMonitorOffset"
setPropertyValue v2 "n-y" y
The cause of this behaviour is apparent in the return value of the first statement of org.simantics.db.layer0.variable.SubliteralPropertyVariable.setValue(WriteGraph, Object, Binding)
, which returns the old asserted value { x = 0.0, y = 0.0 }
, instead of the actual property value { x = 100.0, y = 0.0 }
during the second setPropertyValue
call.