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

Worklog time logged on issue to be incorrect when using some Java methods

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Low
    • None
    • 8.20.10, 9.8.0
    • None

    Description

      Issue Summary

      When the following methods are called for multiple updates very fast,
      jiraissue.timespent table does not get updated correctly. Only the last worklog seems to update the logged hours instead of the sum of the worklogs added.

      This is reproducible on Data Center: yes

      Steps to Reproduce

      I used ScriptRunner console to reproduce the issue.

      1. In a Software project, create an issue and set "Original Estimate" field to 1h

      2. Review jiraissue table in the Jira db for the issue created
        select j.timeoriginalestimate,j.timeestimate, j.timespent,*  from jiraissue j where j.id = 10106
        
        timeoriginalestimate timeestimate timespent id pkey issuenum project reporter
        3600 3600   10106   6 10100 admin

        Note: timespent is empty.

      3. Review worklog table in Jira db
        select w.timeworked,w.updateauthor , u.user_name, u.display_name, w.*
        from cwd_user u
        join app_user a on a.lower_user_name = u.lower_user_name
        join worklog w on a.user_key = w.author
        where w.issueid = 10106
        
        • No rows yet. WorkLog entries have not been added so far.
      4. Execute the below script. It adds two work-log entries for 2 different users. 'admin' will add 1 hour and 'user01' will add 2 hours to the issue. So a total of 3 hours
        import com.atlassian.jira.component.ComponentAccessor
        import com.atlassian.jira.bc.JiraServiceContextImpl
        import com.atlassian.jira.user.ApplicationUser
        import com.atlassian.jira.issue.Issue;
        import com.atlassian.jira.bc.issue.IssueService;
        import com.atlassian.jira.issue.worklog.Worklog;
        import com.atlassian.jira.bc.issue.worklog.WorklogService;
        import com.atlassian.jira.bc.issue.worklog.WorklogInputParametersImpl;
        import com.atlassian.jira.bc.issue.worklog.WorklogResult;
        import com.atlassian.jira.user.util.UserManager;
        
        import java.util.regex.*;
        
        ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
        JiraServiceContextImpl serviceContext = new JiraServiceContextImpl(user)
        IssueService issueService = ComponentAccessor.getComponent(IssueService)
        WorklogService worklogService = ComponentAccessor.getComponent(WorklogService)
        UserManager userManager = ComponentAccessor.getComponent(UserManager)
        
        StringBuilder sbLog = new StringBuilder()
        
        String WORKLOGCOMMENT = "new Comment"
        
        String jiraID = "SC-6"          // <----- PUT JIRA ISSUE ID HERE
        
        def tenroxData = [:]
        tenroxData["admin"] = 1             // <----- PUT VALID USERNAME HERE
        tenroxData["user01"] = 2             // <----- PUT VALID USERNAME HERE
        //tenroxData["admin"] = 40             // <----- PUT VALID USERNAME HERE
        
        Issue issue = issueService.getIssue(user, jiraID)?.getIssue()
        if(issue == null) {
            sbLog.append("\n -- not a valid issue - skipping")
        } else {
        
            tenroxData.each { username, hours ->
        
                ApplicationUser author = userManager.getUserByName(username.toString())
                JiraServiceContextImpl authorServiceContext = new JiraServiceContextImpl(author)
                Date worklogdate = new Date()
                String timespent = hours.toString() + "h"
                WorklogResult worklogResult = worklogService.validateCreate(authorServiceContext, WorklogInputParametersImpl.builder()
                                                                                                        .issue(issue)
                                                                                                        .comment(WORKLOGCOMMENT)
                                                                                                        .startDate(worklogdate)
                                                                                                        .timeSpent(timespent)
                                                                                                        .build())
                if(worklogResult) {
                    worklogService.createAndAutoAdjustRemainingEstimate(authorServiceContext, worklogResult, false)
                } else {
                    sbLog.append("\n" + authorServiceContext.getErrorCollection().toString())
                }
            }
        }
        
        sbLog
        

      Expected Results

      In Jira, "Logged:" field should be 3 hours.

      Actual Results

      In Jira, "Logged:" is set to 2 hours.

      • Review the jiraissue table. timespent = 7200 = 2 hours
        select j.timeoriginalestimate,j.timeestimate, j.timespent,*  from jiraissue j where j.id = 10106
         

                 

        timeoriginalestimate timeestimate timespent id pkey issuenum project reporter
        3600 0 7200 10106   6 10100 admin
      • Review worklog table
        select w.timeworked,w.updateauthor , u.user_name, u.display_name, w.*
        from cwd_user u
        join app_user a on a.lower_user_name = u.lower_user_name
        join worklog w on a.user_key = w.author
        where w.issueid = 10106
        
        • There is an entry for each of the worklog added by the script (7200 = 2 h by admin and 3600 = 1h by user01)
          timeworked updateauthor user_name display_name id issueid author       created
          7200 JIRAUSER10100 user01 user01 10014 10106 JIRAUSER10100       2023-05-09 15:54:02.209 +0200
          3600 admin admin Admin Admin 10013 10106 admin       2023-05-09 15:54:02.203 +0200

      Workaround

      Currently there is no known workaround for this behavior. A workaround will be added here when available

      Attachments

        1. Step_1.png
          Step_1.png
          178 kB
        2. Step_2.png
          Step_2.png
          237 kB
        3. Step_3.png
          Step_3.png
          277 kB

        Activity

          People

            Unassigned Unassigned
            9f03f4114502 Pablo Bartolome
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: