Details
-
Bug
-
Resolution: Unresolved
-
Low
-
None
-
8.20.10, 9.8.0
-
None
-
8.2
-
3
-
Severity 3 - Minor
-
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.
- In a Software project, create an issue and set "Original Estimate" field to 1h
- 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.
- 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.
- 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
- There is an entry for each of the worklog added by the script (7200 = 2 h by admin and 3600 = 1h by user01)
Workaround
Currently there is no known workaround for this behavior. A workaround will be added here when available