decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

🐛 API error when saving entry

Open bradystroud opened this issue 4 years ago • 25 comments

cc: @jackDevAu @pierssinclairssw

Hi,

Describe the bug Some of our users are getting an error when they try to save an entry.

Failed to persist entry: API_ERROR: Not Found

image Figure: Error when saving

After some investigation, it looks like the error occurs when Netlify CMS tries to compare the cms changes branch on the users fork with the main branch on the base repository. e.g. https://api.github.com/repos/SSWConsulting/SSW.Rules.Content/compare/main...JackDevAU:cms/JackDevAU/SSW.Rules.Content/rule/appointments-do-you-show-all-the-necessary-information-in-the-subject/rule

the JackDevAU:cms/JackDevAU/SSW.Rules.Content/rule/appointments-do-you-show-all-the-necessary-information-in-the-subject/rule branch was not created. It is not clear why (see video). The results are the same when using an incoginto window in a different browser.

The problem is resolved after updating the users fork. To try reproduce the problem, we reverted a fork to an old commit, then made a change, but the entry still saved.

To Reproduce We cannot consistently reproduce this error as it is only happening to some of our users. See our video attached below demoing the problem.

Expected behavior The entry should save without error.

Applicable Versions:

  • Netlify CMS core version: 2.54.0
  • Netlify CMS app version: 2.15.59
  • Git provider: GitHub

CMS configuration https://github.com/SSWConsulting/SSW.Rules/blob/main/src/cms/config.js

Additional context https://github.com/SSWConsulting/SSW.Rules/issues/801

https://user-images.githubusercontent.com/38869720/148888815-fba3ec44-c978-45a0-8f3f-d3e99713ef13.mp4

Figure: Demo of the error

bradystroud avatar Jan 11 '22 05:01 bradystroud

This is a becoming a major issue and makes it almost pointless using Netlify CMS.

drwharris avatar Feb 02 '22 23:02 drwharris

This was so painful. Please fix the problem.... or improve that error message please 😢

  • That video explains the problem well.

  • The solution for me was: Github.com | My Profile | Your repositories | Select the forked repo eg. SSW.Rules.Content Click Fetch upstream Click Fetch and merge

     Note: This updates my fork to be usable. When I went back to my edit, I refresh and lost my changes. So I re-did 
    

-a www.adamcogan.com

adamcogan avatar Feb 02 '22 23:02 adamcogan

Hi all and thank you for reporting the issue.

It seems there's a new API to sync forks, see https://docs.github.com/en/rest/reference/branches#sync-a-fork-branch-with-the-upstream-repository

As I'm understanding the issue correctly, we should call that API before saving entries to resolve the issue? If so, would anyone be open to contribute this fix?

erezrokah avatar Feb 03 '22 09:02 erezrokah

cc: @JackDevAU Thanks @erezrokah 🙂, as we aren't familiar with the codebase, could you provide some insight on where this change will need to be added?

bradystroud avatar Feb 10 '22 06:02 bradystroud

Sure @bradystroud, the relevant code is here: https://github.com/netlify/netlify-cms/blob/7bd80b29a43943e5e01a0d7c75573ce02c97f9a3/packages/netlify-cms-backend-github/src/implementation.tsx#L286

We can use the forkExists check and sync the repo if the condition is true. We can probably optimize that code to not call the forks API too

erezrokah avatar Feb 10 '22 10:02 erezrokah

@erezrokah are you looking for something like this?

async authenticateWithFork({
    userData,
    getPermissionToFork,
}: {
    userData: User;
    getPermissionToFork: () => Promise<boolean> | boolean;
}) {
    // ...rest of the code for authenticateWithFork

    if (await this.forkExists({ token })) {
      return fetch(`${this.apiRoot}/repos/${userData.login}/${this.originRepo}/merge-upstream`, {
        method: 'POST',
        headers: {
          Authorization: `token ${token}`,
        },
        body: JSON.stringify({
          branch: this.branch,
        }),
      });
    } else {
      await getPermissionToFork();

      const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
        method: 'POST',
        headers: {
          Authorization: `token ${token}`,
        },
      }).then(res => res.json());
      this.useOpenAuthoring = true;
      this.repo = fork.full_name;
      return this.pollUntilForkExists({ repo: fork.full_name, token });
    }
}

I am also seeing this typescript error down the file, not sure what to make of it:

image

asheerrizvi avatar Jul 03 '22 12:07 asheerrizvi

Hey @asheerrizvi Looks good - Go ahead and create a PR 🙂

bradystroud avatar Jul 04 '22 03:07 bradystroud

Here's the PR, let me know if you guys need any changes: #6504

@erezrokah @bradystroud

😄

asheerrizvi avatar Jul 04 '22 06:07 asheerrizvi

ping: needs to be resolved.

airtonix avatar Mar 14 '23 20:03 airtonix

This is a huge cause of pain for us, @martinjagodic could you please review and action the PR from @asheerrizvi

piers-sinclair avatar Jul 05 '23 01:07 piers-sinclair

We are aware of this problem, we will take a look at the PR soon after we establish the first Decap release. Thanks for your patience 🙏

martinjagodic avatar Jul 05 '23 06:07 martinjagodic

Ping... what is the status of this one? -a www.adamcogan.com

adamcogan avatar Sep 06 '23 09:09 adamcogan

Definitely not fixed - had the same issue a few times recently :(

JeanThirion avatar Sep 07 '23 00:09 JeanThirion

Have seen this issue come up many times recently. Would love to have this resolved!

sethdaily avatar Sep 07 '23 00:09 sethdaily

This issue is in our attention. We are waiting for the PR owner to solve merge conflicts. If he doesn't respond we will do that on a new PR.

martinjagodic avatar Sep 07 '23 06:09 martinjagodic

ping: any updates on this?

RMunschie92 avatar Oct 26 '23 13:10 RMunschie92

The PR is in progress, more details are there. In essence, builds are failing and I was struggling to create a good repoduction. I hope to find some time soon to continue with this.

Any help with the PR would speed things up.

martinjagodic avatar Oct 27 '23 08:10 martinjagodic

This is now released in 3.1.0-beta.1. Can anyone test and confirm that this is solved?

@RMunschie92 @sethdailyssw @JeanThirion @adamcogan @pierssinclairssw @airtonix

martinjagodic avatar Nov 15 '23 14:11 martinjagodic

Can't tell if its fixed because there is a new bug #6924

bradystroud avatar Jan 03 '24 00:01 bradystroud

I still get the error when clicking 'save' after I've made a change, see screenshot: image Figure: Same error

sethdaily avatar Jan 12 '24 02:01 sethdaily

I am still having the same issue on save. It has been 2 years... It's so painful... 😭 image

AntPolkanov avatar Jan 15 '24 23:01 AntPolkanov

@bradystroud I see that many of you are from SSW. Could you find some time together to contribute?

martinjagodic avatar Jan 16 '24 12:01 martinjagodic

Up, is there any update on this issue ?

bastien-germain avatar Apr 03 '24 13:04 bastien-germain

not really I'm afraid

I'm willing to put some effort into this if we find a hero who would describe a very specific scenario on how to (somewhat consistently) reproduce this issue (maybe with a public repo?)

demshy avatar Apr 04 '24 08:04 demshy