Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 5

"Position is invalid" error in posting PR review via v3 API.

My GitHub app (reviewnb.com) routinely posts review comments for pull request without a problem.

 

There's this specific Pull Request in one of our user's private repos that is literally not accepting any review comment via the API. Following is my payload:

 

{
'body': 'This change looks good!', 
'event': 'COMMENT',
'comments': [
  {
    'body': "<p>Can you edit this line?</p>",
    'path': "competitions/water_pumps/notebooks/EDA_adiel.ipynb", 
    'position': 1
  }]
}

I am posting this payload to:

https://api.github.com/repos/<owner>/<repo>/pulls/<pr_number>/reviews

 

The error I am seeing is:

{'message': 'Unprocessable Entity', 'errors': ['Position is invalid'], 'documentation_url': 'https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review'}

 

So it looked like position 1 is not a valid position to post that comment. Which is incorrect because when I fetch the diff of this PR the file diff shows that there are about 670 lines added in this change. So line number 1 in the diff hunk got to be valid.

 

Anyway, I tried all other numbers for the position parameter. But it returns the same error. 

4 Replies
Pilot Lvl 1
Message 2 of 5

Re: "Position is invalid" error in posting PR review via v3 API.

Hi @amit1rrr

 

Try creating a review comment manually then fetching it via the API to look up its position. I'm guessing that for whatever reason, 1 is an invalid position for that PR.

 

Btw was your website design inspired by my old site (for Pull Reminders)? I don't mind at all, was just curious.

 

Copilot Lvl 3
Message 3 of 5

Re: "Position is invalid" error in posting PR review via v3 API.

Try creating a review comment manually then fetching it via the API to look up its position.

I can't. These are private repositories of our users. I haven't been able to reproduce it on any of my repositories.

 

I'm guessing that for whatever reason, 1 is an invalid position for that PR.

This is the strange part. Diff starts with position 1 , so as long as there is at lease 1 line of diff, position 1 should be valid. Any other ideas / things to test?

 

> Btw was your website design inspired by my old site (for Pull Reminders)? I don't mind at all, was just curious.

I'm aware of Pull Reminders but I don't think I have seen your old site, so no. The design is actually inspired by my other product home page: https://www.nurtch.com/ 

 

 

Copilot Lvl 3
Message 4 of 5

Re: "Position is invalid" error in posting PR review via v3 API.

Wrote to support@github.com and provided them with all the requested information. I got following reply:

 

Thanks, Amit -- that's helpful. I believe that's a problem on our end related to creating comments on diffs that are very large (notice that the diff for the file in question is quite large). With that in mind, I've opened an internal issue so that the team can investigate. I can't promise an ETA, but we'll followup as soon as there's any news.

Best,
GitHub Staff

 

I am following up with them to see,
  1. Specific conditions under which this bug occurs (diff size etc.) and see if I can build some work around while they fix the issue.
  2. Follow up to see when they can fix the underlying root cause.
 
I will update the post when I get further updates.
Copilot Lvl 3
Message 5 of 5

Re: "Position is invalid" error in posting PR review via v3 API.

Further updates from GitHub support:

 

Hi there Amit,

Thanks for following up with us. Other integrators have written about this in the last few months and we checked our internal issue for this. Right now, we don't have any updates from the engineering team. We'll be sure to follow up as soon as we get word from them.

Out of curiosity, we're wondering if you could try adding a new review to a Pull Request using the GraphQL API and see if that helps or returns the same 422 error you reported in with?

https://developer.github.com/v4/mutation/addpullrequestreview/

All the best,
GitHub Staff

 

 

As suggested by GitHub, I tried posting comments via GraphQL API and it returns the same error. Posted request response below. Also, I reproduced the issue on a publicly available repository so it's easier for anyone to see. Here's the PR https://github.com/amit1rrr/PythonDataScienceHandbook/pull/42/ & adding comment to file notebooks/05.14-Image-Features.ipynb results in error.

 

GraphQL Request

mutation {
  addPullRequestReview(
    input:{
      clientMutationId: "12344321",
      body: "Looks good to me!",
      event: COMMENT,
      commitOID: "d189b3cb936a853e6d49292930941a162b23ece8",
      pullRequestId: "MDExOlB1bGxSZXF1ZXN0MjU2NzY4NzI3",
      comments: [
        {
          body: "test comment from GraphQL mutation",
          path: "notebooks/05.14-Image-Features.ipynb",
          position: 1
        }
      ]
    }
  )
  {
    clientMutationId
  }
}

 

GraphQL Response

{
  "data": {
    "addPullRequestReview": null
  },
  "errors": [
    {
      "type": "UNPROCESSABLE",
      "path": [
        "addPullRequestReview"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "message": "Position is invalid"
    }
  ]
}