LionWeb-io / lionweb-repository

Reference implementation of LionWeb repository
Apache License 2.0
2 stars 1 forks source link

Crash when executing test twice #19

Closed enikao closed 6 months ago

enikao commented 6 months ago

Starting with an empty database, we execute the following test:

  1. store Disk_A.json
  2. store Disk-add-new-nodes-single-node.json
  3. retrieve ID-2

The first execution works, the second time crashes:

> @lionweb/repository-core@0.1.0 dev
> nodemon dist/server.js

[nodemon] 3.0.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node dist/server.js`
POSTGRES CONFIG: {
  "database": "lionweb_test",
  "host": "localhost",
  "port": 5432,
  "user": "postgres",
  "password": "lionweb"
}
next again
Registering DB Admin
Registering DB Admin
Server is running at port 3005 =========================================================
LionWebQueries.getNodeTree for ID-2,ID-3,ID-4,ID-8,ID-9,ID-10,ID-5,ID-11,ID-12,ID-13,ID-14,ID-15,ID-6,ID-7,ANN-1,ANN-9,ANN-10
Comparing chunks
STORE.CHANGES
[
  '    LanguageAdded: Language with  key -default-key-FileSystem and version 2023.1 is added at $.languages[0] ',
  '    LanguageAdded: Language with  key LionCore-builtins and version 2023.1 is added at $.languages[1] ',
  '    NodeAdded: Node ID-2 is added at $.nodes[0] ',
  '    NodeAdded: Node ID-3 is added at $.nodes[1] ',
  '    NodeAdded: Node ID-4 is added at $.nodes[2] ',
  '    NodeAdded: Node ID-8 is added at $.nodes[3] ',
  '    NodeAdded: Node ID-9 is added at $.nodes[4] ',
  '    NodeAdded: Node ID-10 is added at $.nodes[5] ',
  '    NodeAdded: Node ID-5 is added at $.nodes[6] ',
  '    NodeAdded: Node ID-11 is added at $.nodes[7] ',
  '    NodeAdded: Node ID-12 is added at $.nodes[8] ',
  '    NodeAdded: Node ID-13 is added at $.nodes[9] ',
  '    NodeAdded: Node ID-14 is added at $.nodes[10] ',
  '    NodeAdded: Node ID-15 is added at $.nodes[11] ',
  '    NodeAdded: Node ID-6 is added at $.nodes[12] ',
  '    NodeAdded: Node ID-7 is added at $.nodes[13] ',
  '    NodeAdded: Node ANN-1 is added at $.nodes[14] ',
  '    NodeAdded: Node ANN-9 is added at $.nodes[15] ',
  '    NodeAdded: Node ANN-10 is added at $.nodes[16] '
]
LionWebQueries.getNodeTree for
Queries insert new nodes ID-2,ID-3,ID-4,ID-8,ID-9,ID-10,ID-5,ID-11,ID-12,ID-13,ID-14,ID-15,ID-6,ID-7,ANN-1,ANN-9,ANN-10
LionWebQueries.getNodeTree for ID-20,ANN-1
LionWebQueries.getNodesFromIdList: ANN-1
Comparing chunks
STORE.CHANGES
[
  '    LanguageAdded: Language with  key LionCore-builtins and version 2023.1 is added at $.languages[1] ',
  '    ChildAdded: Node "ANN-1" added child "ID-20" to containment Folder-listing-key at $.nodes[0].containments[0] ',
  '    NodeAdded: Node ID-20 is added at $.nodes[0] '
]
LionWebQueries.getNodeTree for
LionWebQueries.getNodeTree for ID-20
QUERIES insert into "lionweb_containments"("containment","children","node_id") values('{"language":"-default-key-FileSystem","version":"2023.1","key":"Folder-listing-key"}',array['ID-20'],'ANN-1')
-- Up date if not inserted
                ON CONFLICT (node_id, containment)
                DO UPDATE
                    SET "children"=array['ID-20'];
                -- Update of parent of children that have been moved
                UPDATE lionweb_nodes
                    SET "parent"='ANN-1'
                WHERE
                    id = 'ID-20';

Queries insert new nodes ID-20
LionWebBulkApiImpl.retrieve:
Api.getNodes: {"ids":["ID-2"]} depth 9007199254740991
LionWebQueries.getNodeTree for ID-2
LionWebQueries.getNodesFromIdList: ID-2,ID-3,ID-4,ID-5,ID-6,ID-7,ID-8,ID-9,ID-10,ID-11,ID-12,ANN-1,ANN-9,ANN-10,ID-13,ID-14,ID-15,ID-20
LionWebQueries.getNodeTree for ID-2,ID-3,ID-4,ID-8,ID-9,ID-10,ID-5,ID-11,ID-12,ID-13,ID-14,ID-15,ID-6,ID-7,ANN-1,ANN-9,ANN-10
LionWebQueries.getNodesFromIdList: ID-2,ID-3,ID-4,ID-8,ID-9,ID-10,ID-5,ID-11,ID-12,ID-13,ID-14,ID-15,ID-6,ID-7,ANN-1,ANN-9,ANN-10
Comparing chunks
STORE.CHANGES
[
  '    ChildRemoved: Node "ANN-1" removed child "ID-20" from containment "Folder-listing-key" at $.nodes[0].containments[0] '
]
LionWebQueries.getNodeTree for ID-20
$REPO/packages/core/dist/database/Db.js:214
                    SET ${pgp.helpers.sets({ children: afterContainment.children }, CONTAINMENTS_COLUMN_SET)}
                                                                        ^

TypeError: Cannot read properties of undefined (reading 'children')
    at $REPO/packages/core/dist/database/Db.js:214:73
    at Array.forEach (<anonymous>)
    at Db.updateQueriesForRemovedChildren ($REPO/packages/core/dist/database/Db.js:209:25)
    at LionWebQueries.<anonymous> ($REPO/packages/core/dist/database/LionWebQueries.js:136:27)
    at Generator.next (<anonymous>)
    at fulfilled ($REPO/packages/core/dist/database/LionWebQueries.js:4:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.4.0
[nodemon] app crashed - waiting for file changes before starting...
joswarmer commented 6 months ago

@enikao The above seems to work ok, but I see from the log that there should be a third "store" as I see three time STORE.CHANGES. If I am right, what is the third json that is being stored?

joswarmer commented 6 months ago

The third store probably is: ./src/test/data/remove-child/Disk-remove-child-partition.json, right?

enikao commented 6 months ago

I'd think the third store is from the second execution of the test case, so it's probably Disk_A.json again.

joswarmer commented 6 months ago

Found the problem, fix will come soon.

joswarmer commented 6 months ago

Fixed