🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with images not being located in the correct dataset after dataset import in Sanity.io.

29 replies
Last updated: Aug 25, 2021
I just tried to do a dataset import, but images are still located in old dataset. I did not use the “--allow-assets-in-different-dataset” option. Is this expected behavior?
Aug 25, 2021, 8:29 PM
Full command used:
$ npx sanity dataset import data/bak/development_20210825.tar.gz production --replace --replace-assets
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (127ms)
✔ [100%] Importing documents (3.19s)
✔ [100%] Importing assets (files/images) (1m 11.82s)
✔ [100%] Setting asset references to documents (4.35s)
✔ [100%] Strengthening references (1.45s)
Done! Imported 112 documents to dataset "production"
Aug 25, 2021, 8:36 PM
Would love to use the new copy and alias functions, but apparently I need next-level account for that. 😞
Aug 25, 2021, 8:36 PM
Full command used:
$ npx sanity dataset import data/bak/development_20210825.tar.gz production --replace --replace-assets
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (127ms)
✔ [100%] Importing documents (3.19s)
✔ [100%] Importing assets (files/images) (1m 11.82s)
✔ [100%] Setting asset references to documents (4.35s)
✔ [100%] Strengthening references (1.45s)
Done! Imported 112 documents to dataset "production"
Aug 25, 2021, 8:36 PM
Hey User, can you clarify what you mean when you say images are still located in the old dataset?
Aug 25, 2021, 8:39 PM
Full command used:
$ npx sanity dataset import data/bak/development_20210825.tar.gz production --replace --replace-assets
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (127ms)
✔ [100%] Importing documents (3.19s)
✔ [100%] Importing assets (files/images) (1m 11.82s)
✔ [100%] Setting asset references to documents (4.35s)
✔ [100%] Strengthening references (1.45s)
Done! Imported 112 documents to dataset "production"
Aug 25, 2021, 8:36 PM
I’m looking at production dataset, but image paths point to ‘development’ dataset. In some cases, I load the full URL from sanity, and this is fine. But, in one place, I am just grabbing asset ID in my API, and when I place that in context of production dataset to build image path, it comes up 404.
Aug 25, 2021, 8:44 PM
I can see images in the studio while looking at production dataset. Opening image in new window shows it is in development path.
Aug 25, 2021, 8:45 PM
I first encountered this, and then re-ran the import with “replace-assets”. Thought that might fix it. But, no luck.
Aug 25, 2021, 8:46 PM
This also begs the question of what will happen to those images if I delete the development dataset.
Aug 25, 2021, 8:49 PM
Got it. I think what you’re running into is covered in the gotcha in the docs here . You’ll have to reshape your data in this case.
Aug 25, 2021, 8:51 PM
Got it. I think what you’re running into is covered in the gotcha in the docs here . You’ll have to reshape your data in this case.
Aug 25, 2021, 8:51 PM
I do not understand this. Sorry. Can you please explain?
Aug 25, 2021, 8:53 PM
I do not understand this. Sorry. Can you please explain?
Aug 25, 2021, 8:53 PM
I definitely made some new data models. Trying to cleanly push things to production. I see the bit about images tied to datasets. Question is how to migrate them.
Aug 25, 2021, 8:53 PM
“Make sure to bring your assets along for the ride.” is the suggestion in the “gotcha”. How does one do this?
Aug 25, 2021, 8:54 PM
They are present in my export. And the import tool says it re-created assets.
Aug 25, 2021, 8:54 PM
I assumed that the “--replace-assets” (Skip reuse of existing assets) option would solve this for me.
Aug 25, 2021, 8:56 PM
I’m curious if the new dataset copy and alias exhibits this same behavior. Trying to figure out what the proper approach is here. Thanks,
user M
for looking into this.
Aug 25, 2021, 9:02 PM
Hmm, I’m trying to replicate the behavior you’re getting, but it’s not happening on my end. Can you pull up the asset in Vision by running the following query:
*[_id == "<your-image-id>"]{
  path, 
  url
}
Oh and double check that you’ve chosen the right dataset from the drop down in the top-left of the plugin.
Aug 25, 2021, 9:13 PM
I deleted my production dataset, re-created, and imported from my export file to this new dataset without extra options on command line. This time, I think it worked. Rebuilding front-end now to confirm.
Aug 25, 2021, 9:23 PM
I deleted my production dataset, re-created, and imported from my export file to this new dataset without extra options on command line. This time, I think it worked. Rebuilding front-end now to confirm.
Aug 25, 2021, 9:23 PM
Let me know how it goes!
Aug 25, 2021, 9:24 PM
Thank you for the support. I think Sanity is behaving. I have a rather complicated setup with Sanity GraphQL stitched into another GraphQL server and CDN URL’s proxied through CloudFront. Many layers of cache to disrupt things.
Aug 25, 2021, 9:41 PM
Currently, getting a 404 when trying to access a specific image, though. It’s like the 404 is stuck in image CDN cache or something.
Aug 25, 2021, 9:44 PM
Currently, getting a 404 when trying to access a specific image, though. It’s like the 404 is stuck in image CDN cache or something.
Aug 25, 2021, 9:44 PM
Changing the params slightly makes it work. strange.
Aug 25, 2021, 9:45 PM
(probably because I was trying to load this image before it existed in the right “dataset”) Now it is there, and CDN doesn’t realize it?
Aug 25, 2021, 9:46 PM
will add a dummy param to my images to bust this cache. thanks, again.
user M
Much love to the Sanity crew. And, yay for conditional fields. Gratitude.
Aug 25, 2021, 9:48 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?