Watch a live product demo πŸ‘€ See how Sanity powers richer commerce experiences

Troubleshooting a publishing issue with custom workflow actions

44 replies
Last updated: Apr 14, 2020
Can't seem to publish anything all of a sudden when I click on publish it looks like it all worked fine in the ui and network request but the draft label never leaves the item. No console messages.. how can I troubleshoot this?
Apr 14, 2020, 6:15 AM
What about the network pane? Any broken requests?
Apr 14, 2020, 6:16 AM
Nope nothing looks broken in network or console etc
Apr 14, 2020, 6:16 AM
Does it fire a network request when you push publish?
Apr 14, 2020, 6:17 AM
Yup spins the updated just now spinner also and checkbox when finished
Apr 14, 2020, 6:18 AM
And it's persistent on refresh? The publish event doesn't appear in the history view either?
Apr 14, 2020, 6:18 AM
yeah on refresh and history is there it seems
Apr 14, 2020, 6:19 AM
And the publish event is the last event in history? You are sure there isn't any changes being done to the document by a script or custom input component or somesuch? Are you able to retrieve the
drafts._id
document after you have published. Does it e.g have another
_rev
than the published one?
Apr 14, 2020, 6:21 AM
Is it possible to have a circular reference btw I changed a schema to reference something that is also referenced in the items I am referencing?
Apr 14, 2020, 6:23 AM
How do I check that drafts._id and rev?
Apr 14, 2020, 6:23 AM
If you have Vision installed you can take the id (it's the last segment in the URL when you have the editor open (or check the inspector in the upper right corner), and then you can do this:
{
  "published": *[_id == "the-id"][0]{_rev, _updatedAt},
  "draft": *[_id == "drafts.the-id"][0]{_rev, _updatedAt}
}
Apr 14, 2020, 6:25 AM
gotcha ok trying in vision
Apr 14, 2020, 6:26 AM
Just trying to get a sense if it's a UI bug or there's something going on with the publishing machinery
Apr 14, 2020, 6:26 AM
ok before I publish this is the result of that query:
{
  "draft": {},
  "published": {
    "_rev": "sBk7YzjWMuBuhiatU2G1lT",
    "_updatedAt": "2020-04-09T04:43:09Z"
  }
}
After publish it's this:

{
  "draft": {},
  "published": {
    "_rev": "sBk7YzjWMuBuhiatU2G1lT",
    "_updatedAt": "2020-04-09T04:43:09Z"
  }
}
Looks like its not changing
Apr 14, 2020, 6:28 AM
query is
{
  "published": *[_id == "a8ce456b-69e0-436d-b686-26b09a571954"][0]{_rev, _updatedAt},
  "draft": *[_id == "draft.a8ce456b-69e0-436d-b686-26b09a571954"][0]{_rev, _updatedAt}
}
Apr 14, 2020, 6:28 AM
Sorry! it's
drafts.
plural
Apr 14, 2020, 6:29 AM
np trying again
Apr 14, 2020, 6:29 AM
ok before:
{
  "draft": {
    "_rev": "t57dtz-s65-7j8-ljp-odiae3wyd",
    "_updatedAt": "2020-04-14T06:27:57Z"
  },
  "published": {
    "_rev": "sBk7YzjWMuBuhiatU2G1lT",
    "_updatedAt": "2020-04-09T04:43:09Z"
  }
}
after:

{
  "draft": {
    "_rev": "njsqsa-bmq-6qy-j75-ryckt6pn0",
    "_updatedAt": "2020-04-14T06:30:04Z"
  },
  "published": {
    "_rev": "sBk7YzjWMuBuhiatU2G1lT",
    "_updatedAt": "2020-04-09T04:43:09Z"
  }
}
Apr 14, 2020, 6:30 AM
so the published isnt updating?
Apr 14, 2020, 6:30 AM
It seems so
Apr 14, 2020, 6:31 AM
ok i found it
Apr 14, 2020, 6:31 AM
I had this in my publish workflow action:
ops.patch.execute([{ set: { publishedAt: new Date().toISOString() } }]);
bc I want to set the publishedAt time with every publish
Apr 14, 2020, 6:32 AM
seems to be fine in my approve workflow action
Apr 14, 2020, 6:32 AM
thought it was working before also wonder why that would matter in the publish action
Apr 14, 2020, 6:34 AM
Not sure, are you using custom workflow actions in the context you're publishing from?
Apr 14, 2020, 6:34 AM
yeah it's a document action basically just cribbing off the workflow example in the publish action right before this line to publish https://github.com/sanity-io/demo-custom-workflow/blob/master/app/documentActions/workflow/publish.js#L21
Apr 14, 2020, 6:36 AM
on another note I wonder why that `metadata.commit()`line is commented out in the example?
Apr 14, 2020, 6:37 AM
not sure. I suspect this maybe should've been async. I suspect the onComplete fires before the execute has been resolved or something
Apr 14, 2020, 6:38 AM
yeah i think it was a timing issue like the other command yeah exactly
Apr 14, 2020, 6:38 AM
ok that explains it thanks for helping troubleshoot that I pushed that change yesterday so basically nobody could publish today and no-one said anything they were probably confused lol
Apr 14, 2020, 6:39 AM
Apr 14, 2020, 6:39 AM
I wondered why I logged in and everything was draft tonight πŸ™‚
Apr 14, 2020, 6:39 AM
I think I need to check in with the team when their up and about
Apr 14, 2020, 6:40 AM
for the specifics of how this works
Apr 14, 2020, 6:40 AM
woah yeah if I move it before the
metadata.setState('published');
call it works again so could be timing or order with that call in between or something
Apr 14, 2020, 6:41 AM
heart was sunk for a minute there thanks
user Y
as always!
Apr 14, 2020, 6:41 AM
I'm glad there wasn't any data-loss! Except the intention of publishing πŸ™ˆ
Apr 14, 2020, 6:42 AM
yeah was a bit worried they had their first day entering a bunch of data using the system also.. think we're good on that front. It's working now if I move it before that metadata call so final code to work is
  const onHandle = () => {
    if (ops.publish.disabled) {
      props.onComplete();
      return;
    }

    ops.patch.execute([{ set: { publishedAt: new Date().toISOString() } }]);

    metadata.setState('published');
    // metadata.commit()

    ops.publish.execute();
    props.onComplete();
  };
before it was:

  const onHandle = () => {
    if (ops.publish.disabled) {
      props.onComplete();
      return;
    }
    metadata.setState('published');
    // metadata.commit()
    ops.patch.execute([{ set: { publishedAt: new Date().toISOString() } }]);

    ops.publish.execute();
    props.onComplete();
  };
Apr 14, 2020, 6:43 AM
would be nice to know what should be async or not somehow should all these network calls have an await in front of them or called in parallel?
Apr 14, 2020, 6:45 AM
one way I've seen that happen is you provide a network interface wrapper for axios for instance that when called in user land it queues things behind the scenes
Apr 14, 2020, 6:47 AM
anyway I'm good thanks πŸ‘
Apr 14, 2020, 6:47 AM
maybe it has something to do with the state management and that it never reaches the
execute()
methods?
Apr 14, 2020, 6:47 AM
anyways - I'll try to have someone weigh in on this and see if there's any caveats we should put into the docs or somesuch
Apr 14, 2020, 6:48 AM
ok sounds good I'll try to put a breakpoint on that if I can and see whats up
Apr 14, 2020, 6:50 AM
Just a note for your research tomorrow confirmed it's def something with the order of operations not timing.. all of these
ops.patch.execute
calls need to come before any
metadata.setState
call. I had another one being called after and it was having same issue until I moved all the metadata calls after it.
Apr 14, 2020, 7:42 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern content platform that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing