Asset replacement not working as expected

Issue

I have one record that takes exactly one asset.

In my assets collection, I have two records with unique ID’s.
Both assets point to the same “real” media file (URL).
Both of these assets claim to be pointing to my record.

Here’s a link to the actual asset.

Expected behaviour

I would expect that two assets should not point to the exact same media file (URL).
I would expect that when one record has exactly one asset, only exactly one asset should have a link to that item.

Context on my system:
I am guessing that this has occurred during a file replacement.

I replace assets by:

  1. Creating an asset using the uploadLocalFileAndReturnPath function.
  2. Updating my assets with the following command:
client.uploads.update(datoId, { path, upload_collection })

I thought that assets were deleted within 24hrs (link).
As in the preceding image, these assets were last updated 1 week ago.

What I need help with

Understanding how to fix this duplication issue.
Understanding how to prevent this from happening in the future/understanding whether I am replacing assets correctly.

Thanks!

Hey @av,

Hmm, this is a strange one :thinking: In my tests, replacing an existing asset with a new file doesn’t result in the creation of a new duplicate, whether in the UI (which warns you about duplicates) or in the API (which doesn’t automatically detect duplicates, but there’s a parameter which can).

What I tried was right from our example: https://www.datocms.com/docs/content-management-api/resources/upload/update#updaterename-assets

  // associate a new file with the existing upload object:
  await client.uploads.update(uploadId, {
    path: await uploadLocalFileAndReturnPath(client, "./image.jpg", {
      // if you want, you can specify a different base name for the uploaded file
      filename: "different-image-name.png",
    }),
  });

Your workflow sounds similar, but apparently something went wrong…? You may have found a bug or edge case? Would you mind sharing your upload script, please, so I can try to replicate it and report it? I’m not sure exactly what you did to get to this state, but it’s not intended behavior for sure… sorry about that :slight_smile:

Hopefully with a bit more code, I can make it happen and report it for fixing!