Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-78662

Deleting Jira issue comments using the Jira Java API "com.atlassian.jira.issue.comments.CommentManager.delete" does not update the comment_version table if we set dispatchEvent as false.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Low Low
    • None
    • 9.12.18, 9.12.19, 10.4.1
    • Java API

      Issue Summary

      Deleting Jira issue comments using the Jira Java API "com.atlassian.jira.issue.comments.CommentManager.delete" does not update the comment_version table if we set dispatchEvent as false.

      Steps to Reproduce

      1. Create a Jira instance on version 9.12.18 or 9.12.19
      2. Create a Project and a Jira issue under the project.
      3. Assume the Jira issue key created is "ABC-1"
      4. Create a few comments on ABC-1
      5. Use the below Java API script to delete the comments from the Jira issue "ABC-1".
        import com.atlassian.jira.component.ComponentAccessor
        import com.atlassian.jira.issue.Issue
        import com.atlassian.jira.issue.IssueManager
        import com.atlassian.jira.issue.comments.Comment
        import com.atlassian.jira.issue.comments.CommentManager
        import com.atlassian.jira.user.ApplicationUser
        
        // Define the specific issue key
        String issueKey = "ABC-1"
        
        IssueManager issueManager = ComponentAccessor.getIssueManager()
        CommentManager commentManager = ComponentAccessor.getCommentManager()
        
        // Get the specific issue by the issue key
        Issue issue = issueManager.getIssueByKeyIgnoreCase(issueKey)
        
        if (issue) {
            // Get comments for the specific issue
            List<Comment> userComments = commentManager.getComments(issue).findAll { comment ->
                comment.getAuthorApplicationUser() == getUser("admin")
            }
            
            // Delete the comments
            if (userComments) {
        
                    userComments.each { comment ->
                    commentManager.delete(comment, false, getUser("admin"))
                }
            }
        }
        
        ApplicationUser getUser(String userName) {
            return ComponentAccessor.getUserManager().getUserByName(userName)
        }
        
      1. I've used ScriptRunner plugin console to execute the script.

      Expected Results

      All the comments will be deleted from the Jira issue, and the "index_version" (e.g., 1 -> 2) and "deleted" (N -> Y) columns of the "comment_version" table should be updated.

      Actual Results

      All the comments from the Jira issue are getting deleted, but the changes are not reflected in the "comment_version" table.

      Workaround

      The workaround is to set "dispatchEvent=true" while initiating the Java API.

              Unassigned Unassigned
              e6507c4d83bb Vaisakh S
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: