Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-12953

Adding a comment to a deleted PR using java can cause a participant gets added to it.

    XMLWordPrintable

Details

    Description

      Issue Summary

      When a user is able to re-insert a PR into the database using java API, it is able to insert a row without the author. Since this is not valid, attempting to load that PR will throw 500 response code. 

      Steps to Reproduce

      1. Create a PR, and delete it immediately, using UI or API.
      2. Add a comment with the following code in script runner
        import com.atlassian.bitbucket.event.pull.PullRequestOpenedEvent
        import com.atlassian.bitbucket.comment.AddCommentRequest
        import com.atlassian.bitbucket.comment.CommentService
        import com.atlassian.sal.api.component.ComponentLocator
        
        def commentService = ComponentLocator.getComponent(CommentService)
        
        def event = event as PullRequestOpenedEvent
        def pullRequest = event.getPullRequest()
        def repository = pullRequest.toRef.repository
        
        def allowedRepos = ["repo 1"]
        
        if (repository.slug in allowedRepos) {
        sleep(15000)
        def addCommentRequest = new AddCommentRequest.Builder(pullRequest,"Random comment").build()
        def comment = commentService.addComment(addCommentRequest)
        }
        
      1. If the PR is deleted just before the comment was added, it automatically adding the lines to sta_pull_request and then sta_pr_participant table with pr_role=2

      Expected Results

      If a PR is already deleted, it should not add a participant to that same PR

      Actual Results

      Participant gets added to PR and loading that PR returns a 500 response.

      The below exception is thrown in the atlassian-bitbucket.log file:

      2021-08-04 09:50:45,506 ERROR [http-nio-7990-exec-36] carlos.medina.sanchez.next *1NPM376x590x319680x5 14t3kb8 62.83.237.247,62.83.237.247,10.10.22.86,10.80.21.188 "GET /projects/XPIS/repos/clan_murex/pull-requests HTTP/1.1" c.a.s.i.r.renderer.AggregateBuilder Failed to create the JSON surrogate for an object of type com.atlassian.stash.internal.pull.InternalPullRequest
      java.lang.RuntimeException: Failed to instantiate surrogate instance
      .
      .
      Caused by: java.lang.IllegalStateException: Pull request author could not be found in its participants
      	at com.atlassian.stash.internal.pull.InternalPullRequest.getAuthor(InternalPullRequest.java:193)
      	at com.atlassian.bitbucket.rest.pull.RestPullRequest.<init>(RestPullRequest.java:106)
      	... 102 common frames omitted
      

      Workaround

      Make sure to add a check in the script to confirm if the PR is not deleted.

      If there is a need to fix the 500 error and you do not have a backup to restore, reach out to Atlassian Support for assistance.

      Attachments

        Issue Links

          Activity

            People

              khughes@atlassian.com Kristy
              bd8dd603031e CARLOS MEDINA SANCHEZ
              Votes:
              16 Vote for this issue
              Watchers:
              23 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: