Cannot update block in localized modular content

I have a model with a localized modular content block.

Whenever I try to use the datocms-client API to update the model within a migration, I get the following error: “Invalid block record ID: 77625081. It does not belong to the Item”, even if I just save the item IDs as they originally are received.

An example that replicates this problem (with some object names changed):

let item = (await client.items.all({ filter: { type: 'my_item_type' }, page: { limit: 1 } }))[0];
// => { "id": ..., "modular_field": { "en": [ ... ] } }

await client.items.update(, { modular_field: { en: item.modular_field.en } })
// => {"field":"modular_field.en","code":"INVALID_FORMAT","message":"Invalid block record ID: 77625081. It does not belong to the Item"}
// => {"data":{"id":"77628769","type":"item","attributes":{"modular_field":{"en":["77625079","77625080","77625081","77625082","77623017","77623018","77623019","77623020","77618529","77618184"]}}}}

Never mind, I found that the real cause was because the model was somehow still referencing blocks that did not exist in the database. I am not sure when or how that happened, but the clue was that there were a different number of modular_field items depending on whether I queried with { nested: true } or not.

Hello @seth.jeffery not sure if this is a bug or not, but I’m not sure if it’s clear that using nested: true will automatically get all the blocks’ content together with the record. So you get the full record+blocks in one single call, instead of getting the IDs and then fetching the blocks separately. Not sure if this caused any misunderstanding?