Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxResult should allow values >= 0 #1823

Open
3 of 4 tasks
jstafford5380 opened this issue Feb 16, 2024 · 1 comment
Open
3 of 4 tasks

maxResult should allow values >= 0 #1823

jstafford5380 opened this issue Feb 16, 2024 · 1 comment

Comments

@jstafford5380
Copy link

jstafford5380 commented Feb 16, 2024

Bug summary

The API allows for specifying fewer than 50 results, so should the SDK. For example, I want to even be able to set 0 if I just want to get the count for the query result, which currently, I cannot.

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

cloud

jira-python version

3.6.0

Python Interpreter version

3.10.6

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Use `client.search(maxResults=0)`
# 2. Observe the request URL in logs, the maxResults param has been changed to 100
# 3. Execute the same request in Postman and observe the server responds with an empty array but with counts.

Example code


 unplanned = client.search_issues(
        jql_str=f'project = {project} '
                f'AND type != subtask '
                f'AND priority = Highest '
                f'AND created >= {start} AND created >= {end}',
        maxResults=0
    )

I believe the problem is here:

jira/jira/client.py

Lines 732 to 735 in 0975053

if maxResults:
page_params["maxResults"] = maxResults
elif batch_size := self._get_batch_size(item_type):
page_params["maxResults"] = batch_size

There is a statement if maxResults: which evaluates to false when zero and the fo.lowing elif statement sets it to a batch size of 100. I find it strange to use an int as a boolean in this way, so I wonder if this was intended.

Stack trace

In my case it was revealed during an unrelated error (notice maxResults at the end of the URL)

jira.exceptions.JIRAError: JiraError HTTP 400 url: https://redacted.net/rest/api/2/search?jql=project+%3D+PENG+AND+type+%21%3D+subtask+AND+priority+%3D+Highest+AND+created+%3E%3D+2024-01-01+AND+created+%3E%3D+2024-02-16&startAt=0&validateQuery=True&fields=%2Aall&maxResults=100
	text: The value 'PENG' does not exist for the field 'project'., Field 'type' does not exist or this field cannot be viewed by anonymous users., Field 'priority' does not exist or this field cannot be viewed by anonymous users.

Expected behaviour

When I set maxResults=0 then that is what should be sent to the server.

Additional Context

No response

@rynkk
Copy link
Contributor

rynkk commented Mar 1, 2024

I agree that the way this is handled probably is not the most elegant, but maybe this workaround can alleviate the pain, while people check if this misbehaviour is worth adjusting:

Set maxResult to "0" instead of 0, e.g.:

 unplanned = client.search_issues(
        jql_str=f'project = {project} '
                f'AND type != subtask '
                f'AND priority = Highest '
                f'AND created >= {start} AND created >= {end}',
        maxResults="0"
    )

Jannik Meinecke [email protected] on behalf of MBition GmbH.

Provider Information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants