pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.92k stars 857 forks source link

Not differentiating between an error and no result on user search #1804

Open cheshirex opened 5 months ago

cheshirex commented 5 months ago

Bug summary

I encountered some failures in my testing yesterday where Jira was intermittently failing to find a user who exists. The error is no longer occurring, but I'm theorizing that I was getting rate-limiting errors on the query.

The problem is that the call to search_users just returned an empty list. From what I can see, the call stack is search_users -> _fetch_page -> _get_json, which does not seem to check the status code of the get call, but instead blindly calls json_loads on the response, which will result in an empty list. Since an empty list is a valid response in the case where a successful search doesn't find a user, I can't differentiate between the case where the user isn't found and when the search failed because of some error.

Thanks!

Is there an existing issue for this?

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.6.0

Python Interpreter version

3.9

Which operating systems have you used?

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call search_users with a user that I know exists
result = jira.search_users(query='I_exist@company.com')
# 3. But we are currently being rate-limited by Atlassian cloud
# At this point result is an empty list -- but I would expect an exception to have been raised.

Stack trace

Note that there was no error/exception from the jira package.
The stack including line numbers from PyCharm from a normal user search call from my test:
_get_json, client.py:3939
_fetch_pages, client.py:737
search_users, client.py:3571
<module>, scratch.py:79

Expected behaviour

If the HTTP response code is not 2xx, I would expect a JIRAError exception to be raised

Additional Context

No response