decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.8k stars 3.03k forks source link

πŸ› API error when saving entry #6116

Open bradystroud opened 2 years ago

bradystroud commented 2 years ago

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:

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

drwharris commented 2 years ago

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

adamcogan commented 2 years ago

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

-a www.adamcogan.com

erezrokah commented 2 years ago

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?

bradystroud commented 2 years ago

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?

erezrokah commented 2 years ago

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

asheerrizvi commented 2 years ago

@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
bradystroud commented 2 years ago

Hey @asheerrizvi Looks good - Go ahead and create a PR πŸ™‚

asheerrizvi commented 2 years ago

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

@erezrokah @bradystroud

πŸ˜„

airtonix commented 1 year ago

ping: needs to be resolved.

piers-sinclair commented 1 year ago

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

martinjagodic commented 1 year ago

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 πŸ™

adamcogan commented 1 year ago

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

JeanThirion commented 1 year ago

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

sethdaily commented 1 year ago

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

martinjagodic commented 1 year ago

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.

RMunschie92 commented 10 months ago

ping: any updates on this?

martinjagodic commented 10 months ago

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 commented 10 months ago

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

bradystroud commented 8 months ago

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

6924

sethdaily commented 8 months ago

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

AntPolkanov commented 8 months ago

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

martinjagodic commented 8 months ago

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

bastien-germain commented 5 months ago

Up, is there any update on this issue ?

demshy commented 5 months ago

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?)

mohab-sameh commented 3 months ago

@demshy Commenting as I had several people I know report the same thing. Somehow it got resolved by deleting and re-inviting the user in Netlify identity. Willing to help with testing but can't consistently reproduce it. However, it's a major blocker when it happens..