StoredCalcRefreshHandler Exception when trying to remove an object


I’m seeing an error when I try to remove an instance of Facility (a type with bunch of fields and some stored calc fields), and the object is not removed:

Facility.create({id: '01', systemSize: 1})
. . .
Facility.remove('01') // or Facility.get('01').remove()
C3.client.ActionError {name: "ActionError", message: "Internal error: Error in StoredCalcRefreshHandler: ", error: C3.t…s.Obj, stack: "Error: Internal error: Error in StoredCalcRefreshH…78:20), <anonymous>:4:22)↵    at <anonymous>:1:20"}
error:C3.typesys.Obj {id: "50.3127", codes: Array(1), key: "c3.engine.database.DbException_storedCalcRefreshHandlerException", template: "Internal error: {}", parameters: ["Error in StoredCalcRefreshHandler: ", "c3.engine.database.connector.ConnectionException: … should not be called for non-persistable fields!"], _type: {…}}
message: "Internal error: Error in StoredCalcRefreshHandler: "
"Error: Internal error: Error in StoredCalcRefreshHandler: ↵    at new C3.client.ActionError (http://localhost:8080/typesys/1/all.js?env=browser&compat:1129:13)↵    at Object.request (http://localhost:8080/typesys/1/all.js?env=browser&compat:881:15)↵    at (http://localhost:8080/typesys/1/all.js?env=browser&compat:566:27)↵    at c3Call (http://localhost:8080/typesys/1/all.js?env=browser&compat:99:20)↵    at Object._call0 (http://localhost:8080/typesys/1/all.js?env=browser&compat:2664:20)↵    at Object.eval (eval at get (http://localhost:8080/typesys/1/all.js?env=browser&compat:3078:20), <anonymous>:4:22)↵    at <anonymous>:1:20"

Any idea on how to fix this?



It seems that the problem was related to a stored calc that depends on another calc field, but the strange thing it’s that this was in another type than Facility. Here is the state before the fix:

type Device {
  . . .
  parentDevice: Device calc "parent"
  orgs: [Organization] stored calc "facility ? facility.orgs : parentDevice.facility.orgs"

The fix was to make parentDevice a calc stored field:

  parentDevice: Device stored calc "parent"

Why is that?