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

[Jira] Fix get method data retrieval failures when advanced mode is on #1449

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

gibsramen
Copy link
Contributor

Relevant to #1137, #501

Background

A couple methods in Jira use chained method calls to retrieve data immediately after querying the API. For example, the get_issue_link_types method returns the data with the following line:

return (self.get(url) or {}).get("issueLinkTypes")

With advanced mode off, this is no problem because the first .get call returns a dictionary upon which the next .get operates. However, with advanced mode on, the result of the first .get is a requests.Response object. This class has no .get method, leading to the following error:

AttributeError: 'Response' object has no attribute 'get'

Changes

This PR adds a helper method in the underlying AtlassianRestAPI object, _get_response_content to help with retrieving API data regardless of the status of advanced_mode. This method takes the same arguments as AtlassianRestAPI.get with one additional requirement: fields. This is a list of tuples of the format (<field name>, <default value>). These fields are used for getting the data out of the API JSON. Note that including a default value is optional.

You can pass in multiple fields and they will be sequentially queried. E.g. if the response looked like the following:

{
    "field1": {
        "field2": {
            "field3": "A"
        }
    }
}

you could query it with self._get_response_content(url, fields=[("field1",), ("field2",), ("field3",)]) and return "A"

The following methods have been updated to use this new method:

  • get_issue_link_types
  • get_issue_labels
  • get_issue_status
  • get_issue_status_id
  • get_project_actors_for_role_project
  • get_status_id_from_name
  • get_issue_link_types
  • get_all_permissionschemes
  • get_issue_security_schemes
  • get_issue_security_scheme

_get_response_content is to be used for chaining together response
retrieval. This is useful in the case where you are querying the API and
then immediately extracting some data from the response. This method is
needed to account for the case where advanced mode is on and the initial
get call returns a requests.Response rather than a dictionary.
For methods that query the API and then immediately retrieve some data
from the response, replace the get call with the new
_get_response_content method to account for advanced mode usage.
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 4.00000% with 24 lines in your changes missing coverage. Please review.

Project coverage is 34.35%. Comparing base (e9520ab) to head (41075ac).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
atlassian/jira.py 0.00% 12 Missing ⚠️
atlassian/rest_client.py 7.69% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1449      +/-   ##
==========================================
- Coverage   34.40%   34.35%   -0.05%     
==========================================
  Files          46       46              
  Lines        8606     8621      +15     
  Branches     1604     1608       +4     
==========================================
+ Hits         2961     2962       +1     
- Misses       5520     5534      +14     
  Partials      125      125              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gonchik gonchik merged commit f146a9b into atlassian-api:master Sep 3, 2024
10 of 12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants