sanity
sanity copied to clipboard
Improve unpublish/delete error when referenced somewhere
Is your feature request related to a problem? Please describe. Unpublish and delete a doc can fail with a vague error about being possibly linked somewhere.
Describe the solution you'd like We should be able to unpublish or delete anything (with a warning/confirmation) and the other linked item should have a graceful fallback if it is deleted or unpublished. This is how Contentful handles it. The reason is a user may need to remove a page from the live site and they are basically stuck at that point if they can't unpublish or delete it.
Also, one basic rule of User Interfaces is you never leave your user hanging with nowhere to go. The message is not user friendly. At a minimum the message should at least tell you exactly what is linking to it in a friendly way and easily allow you to discover those associations and remove them to resolve the problem.
This is a real problem for me right now because I am building a workflow where documents are approved (+ published automatically) or disapproved (+ unpublished automatically) and basically a user is going to disapprove a doc and run into this error because it might be already used on the site and there is no good way around it for them.
Describe alternatives you've considered
Using a published at field is a hack around the system and is not intuitive to the published/draft model. If I set a published at field to the future for instance to get around this issue it will show the doc was published message fly in which is confusion, it was disapproved but published?
Additional context

Can we at least set the publishedAt field to null in the meantime? I tried doing that and it said invalid value for dateTime. Now I need to filter all future dates from rendering in all my page datas? 😢
"Weak" references might help here. https://www.sanity.io/docs/reference-type#example-weak-reference-f45f659e7b28
Thanks @tkdave I'll look into that! Is there any drawback to making everything a weak reference?
Even with using a weak reference I still feel the UI could use a better way for a regular user to resolve this and not being stuck.
Hi Zane – that dialogue should link to the documents doing the referencing so the user can go remediate it. Marking the references as weak will allow deletion, but will leave you with dangling references.
We'll look into why this dialogue isn't more helpful. Thank you for bringing it to our attention.
In this case, how am I supposed to delete the documents that are preventing me deleting another document?
great question @D-Pagey
I do have the same issue as @D-Pagey asked. I already deleted the document that had the reference and now I'm actually trying to delete the Reference itself and I'm getting an error that it still linked to the one that was already deleted. Is there a way to improve this binding?
Getting this same error myself. Something to do with a draft preview referring to it.


@D-Pagey @tailanedebrito @JayBox325
Anyone found a fix for this?
Thanks for reporting! This should be fixed in newer versions of Sanity Studio.
Thanks for reporting! This should be fixed in newer versions of Sanity Studio.
![]()
This is still happening to me, @sanity/cli version 3.9.1
Thanks for reporting! This should be fixed in newer versions of Sanity Studio.
![]()
Still happening. The prompt you posted does appear, but after clicking "Delete anyway", it still shows the error:
An error occurred while attempting to delete this document. This usually means that there are other documents that refers to it. Details Mutation(s) failed with 1 error(s)
We are getting something similar on 3.49; the details didn't list the places to go, and different users got a different presentation (some had the elaborate UI, some got this toast notification).