Impossible cannot save without an ID error

I wanted to modify the aragon-tokens subgraph (explorer), adding a simple lastUpdateAt so I can query only the info that has been updated since the last request. I’ve never programmed on wasm before, but after reading all the docs about a graph, I got to it and it seemed pretty simple.

I just had to modify the schema.graphql and the file where the item its created/modified. Here are my modifications. Pretty simple, huh? Or so I thought, because when I wanted to deploy it, I saw the following indexing errors:

30/11/2021, 16:43:29 INFO Done processing trigger, data_source: MiniMeToken, handler: handleTransfer, total_ms: 40, address: 0x8664…56d7, signature: Transfer(indexed address,indexed address,uint256), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 ERROR Handler skipped due to execution failure, error: Mapping aborted at generated/schema.ts, line 23, column 4, with message: Cannot save TokenManager entity without an ID wasm backtrace: 0: 0x1864 - <unknown>!generated/schema/TokenManager#save 1: 0x1a53 - <unknown>!src/aragon/mappings/MiniMeToken/_getMiniMeTokenEntity 2: 0x1c92 - <unknown>!src/aragon/mappings/MiniMeToken/handleTransfer , handler: handleTransfer, block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Done processing trigger, data_source: democracy-kit@1.0.0, handler: handleInstalledApp, total_ms: 13, address: 0x705c…4444, signature: InstalledApp(address,bytes32), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 ERROR Handler skipped due to execution failure, error: Heap access out of bounds. Offset: 131056 Size: 20 wasm backtrace: 0: 0x1370 - <unknown>!~lib/@graphprotocol/graph-ts/index/DataSourceTemplate.create 1: 0x17a4 - <unknown>!src/aragon/aragon/processApp 2: 0x17d3 - <unknown>!src/aragon/mappings/DAOKit/handleInstalledApp , handler: handleInstalledApp, block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Done processing trigger, data_source: democracy-kit@1.0.0, handler: handleInstalledApp, total_ms: 23, address: 0x705c…4444, signature: InstalledApp(address,bytes32), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Done processing trigger, data_source: democracy-kit@1.0.0, handler: handleInstalledApp, total_ms: 23, address: 0x705c…4444, signature: InstalledApp(address,bytes32), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Done processing trigger, data_source: democracy-kit@1.0.0, handler: handleInstalledApp, total_ms: 24, address: 0x705c…4444, signature: InstalledApp(address,bytes32), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Done processing trigger, data_source: DAOFactory@0.6, handler: handleDeployDAO, total_ms: 25, address: 0x595b…c559, signature: DeployDAO(address), block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:29 INFO Create data source, params: 0x5469f7412d84352790c758b3036c49e5cde996aa, name: Kernel, block_hash: 0x0fdab033f49667ee506742ad00a563b30b7f8099c2e4d8adc26cfe2b28391268, block_number: 6899653
30/11/2021, 16:43:27 INFO Applying 2 entity operation(s), block_hash: 0x8bede742feb4a8b4ea4fd52d240315499f1e60b8b5773128c68421bec6e4c76c, block_number: 6899524

Given the following code, I think it’s impossible to .save() the miniMeToken without it having an ID.

  let miniMeTokenEntity = MiniMeTokenEntity.load(miniMeTokenEntityId)
  if (!miniMeTokenEntity) {
    // assign the values

    miniMeTokenEntity.save()
  }

Perhaps this is related to the error: Heap access out of bounds?

How could I improve this question? What resources are available to learn more about modifying subgraphs?

Hi @ddavo! This in-progress issue actually automatically does what I think it is you are trying to do with this update: GraphQL: Add filter that only matches entities changed since a given block · Issue #1838 · graphprotocol/graph-node · GitHub
However in general questions about subgraph development are better asked in the Graph Protocol Discord
And to answer your specific question, yes, entities require an ID field to be saved

1 Like