Warning: Stale Persistent Objects created by $THIS
tl;dr I have discovered that using $THIS in a very specific way will make persistent objects go stale.
I found that it only happens when using $get on an array that contains the OID reference of $THIS. I assume that this is an unwanted feature and have raised a WRC. The problem can be recreated following the steps below, I have also posted the workaround that I am currently testing and looks to be working fine.
1. Create a persistent class...
Property SomeValue As %String;
//this will cause $THIS to go stale in this process
if $get(seen($THIS)) quit
ClassMethod Initialise() As %Status
ClassMethod Update() As %Status
2. Open up a terminal and...
3. Open a second terminal and...
Note, it's when calling SomeMethod() that this object will become stale.
4. In the first terminal...
5. In the second terminal...
You will see that the second terminal still has a stale version of the persistent object.
These stale objects are also apparent in CSP sessions.
Thanks to Timothy for a simpler workaround...
Appending an empty string prevents the side effect.
Instead of using the OID value of $THIS directly, create a separate variable and create a stringy value of the OID... set oid=$lg($THIS."%%OID",1)_"@"_$lg($THIS."%%OID",2) Using the oid variable instead of $THIS makes the problem go away.