Return more than 5000 worklogs for a given issue using hte Python

Agustin Rovero
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 11, 2024

Hi there!

First of all, let me say that this question was already asked in the link below, but has not been solved. The last reply was in December 2022.

https://community.atlassian.com/t5/Jira-questions/Return-more-than-5000-worklogs-for-a-given-issue/qaq-p/2215910

 

I´ve been using the jira module that I believe is the official one and the worklogs function doesn't have a maxResults parameter.

I'm using jira==3.8.0

This is my code (with credentials and issue name removed):

from jira import JIRA
import jira

jira_options = {'server':server}
credentials = (email,token)

client = JIRA(options = jira_options,basic_auth = credentials)

issue = client.issue('myissue')
print(a.fields.worklog.total) # This line prints 9574 in my case.

# Can't use maxResults, I get:
# TypeError: worklogs() got an unexpected keyword argument 'maxResults'
work = self.client.worklogs(issue = issue) # Without maxResults it works.
print(len(work)) # This line prints 5000.

Thank you

1 answer

0 votes
Clark Everson
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2024

Hi @Agustin Rovero 

The limit for max results is set on the server side, 5000 is actually very high! Generally it's 1000

You would need to set a loop to go through pages

This is the code we use:

# Run the JQL query and get the projects
proj_dict = {}
while True:
issues = jira.search_issues(jql_query, maxResults=max_results, startAt=start_at)

# If no issues are returned, we're done.
if not issues:
break

# Extract the key, project name, and project lead from the issues
for issue in issues:
project_key = issue.fields.project.key
project_name = issue.fields.project.name
if project_key not in proj_dict:
jra = jira.project(project_key)
proj_dict[project_key] = jra
else:
jra = proj_dict[project_key]
project_lead = jra.lead.displayName
project_data.append({
'project_key': project_key,
'project_name': project_name,
'project_lead': project_lead,
})

# Update startAt for the next batch of issues.
print(project_data[start_at:start_at+max_results])
start_at += max_results
print(len(project_data))

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events