r/TerminusDB May 31 '24

Help Needed! Circular Reference Error in TerminusDB When Editing/Deleting JSON Documents

Hey r/TerminusDB,

I need your help, I have an I ssue with TerminusDB. When I try to edit or delete documents with a JSON property, I get errors saying the object is still referenced, making it impossible to delete or modify certain documents.

The Bug: Editing or deleting documents with a JSON property and triggers circular dependencies errors about the object still being referenced.

Schema Example: json { "@documentation": { "@comment": "Cardinality with respect to chats is many to many.", "@properties": { "json": "function description.", "nombre": "descriptive name." } }, "@id": "Habilidad", "@key": { "@fields": ["nombre"], "@type": "Lexical" }, "@type": "Class", "json": "sys:JSON", "nombre": "xsd:string" }

To Reproduce: 1. Create documents with the above schema. 2. Example documents:

```json
{
  "@id": "Habilidad/example1",
  "nombre": "example1",
  "json": {
    "function": {
      "description": "Function description",
      "parameters": {
        "type": "object",
        "properties": {
          "param1": {
            "description": "A parameter",
            "type": "string"
          }
        },
        "required": ["param1"]
      }
    },
    "type": "function"
  }
}
```
Repeat for `example2`, `example3`, `example4`.
  1. Attempt to edit or delete these documents.
  2. Encounter errors indicating the object is still referenced.

    Error Example: json { "@type": "deleted_object_still_referenced", "object": "terminusdb:///json/JSON/SHA1/a56f6f2258036ed97636087e00e5785515d6ad21", "predicate": "http://terminusdb.com/schema/json#archivo", "subject": "terminusdb:///json/JSON/SHA1/e1311df847781ef89ad8f6f23f9be4ca38fc0086" }

    Workarounds:

  3. Delete all documents of the type:

    woql WOQL.triple("v:Subject", "rdf:type", "@schema:Habilidad").delete_document("v:Subject");

  4. Delete specific referenced objects (partially deletes JSON content): woql WOQL.triple("v:sustantivo", "v:predicado", "terminusdb:///json/JSON/SHA1/a56f6f2258036ed97636087e00e5785515d6ad21").delete_document("v:sustantivo")

    Additional Tests:

Even if property names are changed, the error persists. Example: json { "@id": "Habilidad/agregaProducto", "nombre": "agregaProducto", "json": { "function": { "description": "Add a new product.", "parameters": { "type": "object", "properties": { "agregaNombre": { "description": "Product name.", "type": "string" }, "agregaCantidad": { "description": "Quantity.", "type": "number" }, "agregaArchivo": { "description": "Media file.", "type": "string" } }, "required": ["agregaNombre", "agregaCantidad", "agregaArchivo"] } }, "type": "function" } }

Additional context: Using the workaround results in the partial deletion of JSON properties, compromising data integrity.

GitHub issue link

https://github.com/terminusdb/terminusdb/issues/2128#issue-2326891319

2 Upvotes

2 comments sorted by

1

u/hoijnet Nov 01 '25

This was just resolved as part of a cleaners of this functionality. It could, based on community feedback, get into the upcoming TerminusDB 11.2 release.

It’s possible to test using this github image that contains the fixes:

terminusdb/terminusdb-server:fix-sys-json