rhevm-qe-automation / pytest_jira

py.test plugin to integrate with JIRA
GNU General Public License v2.0
29 stars 25 forks source link

Python-jira failed with JsonDecoder exception #105

Closed gs202 closed 5 years ago

gs202 commented 5 years ago

Setup: We have a wrapper (wrapper_jira_issue) for pytest_jira that logs the result in case of an HTTP error and retries the call.

Scenario: When test runs, the flow checks for several jira tickets one by one. For unknown reason, JsonDecoder exception occurred.

Expected result: get_issue response should handle with json response

request = <SubRequest 'file_api_provider' for <Function test_file_creation_and_properties[docx-vendor:box_box_casb_license]>>
init_api_container = <function init_api_container.<locals>._init_api_container at 0x7f0d1f49e0d0>

    @pytest.fixture
    def file_api_provider(request, init_api_container):
>       return init_api_container(request.param)

internal/fixtures/container.py:247: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
internal/fixtures/container.py:51: in _init_api_container
    attach_container(container)
internal/fixtures/container.py:31: in _
    test_skipper()
internal/fixtures/test_related.py:123: in _
    if issue.match(**conditions, jira_issue=jira_issue, get_closest_marker=get_closest_marker):
models/skip_issue.py:55: in match
    conditions.append(jira_issue(self.conditions.jira_issue))
utils/retrier.py:24: in retry_decorator
    rv = retry_call(f, fargs, fkwargs, exceptions, tries, delay, max_delay, backoff, jitter, log)
.eggs/retry-0.9.2-py3.6.egg/retry/api.py:101: in retry_call
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, logger)
.eggs/retry-0.9.2-py3.6.egg/retry/api.py:33: in __retry_internal
    return f()
internal/fixtures/test_related.py:137: in _
    return jira_issue(ticket)
.eggs/pytest_jira-0.3.10-py3.6.egg/pytest_jira.py:514: in wrapper_jira_issue
    return not jira_plugin.is_issue_resolved(issue_id)
.eggs/pytest_jira-0.3.10-py3.6.egg/pytest_jira.py:66: in is_issue_resolved
    self.issue_cache[issue_id] = self.conn.get_issue(issue_id)
.eggs/pytest_jira-0.3.10-py3.6.egg/pytest_jira.py:223: in get_issue
    issue = self._jira_request(issue_url).json()
.eggs/requests-2.20.1-py3.6.egg/requests/models.py:897: in json
    return complexjson.loads(self.text, **kwargs)
/usr/lib/python3.6/json/__init__.py:354: in loads
    return _default_decoder.decode(s)
/usr/lib/python3.6/json/decoder.py:339: in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <json.decoder.JSONDecoder object at 0x7f0d3013bcf8>
s = '{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"66816","self":"h...Type":"atlassian"},"created":"2019-07-22T01:28:26.738-0700","updated":"2019-07-22T01:28:26.738-0700","jsdPublic":true}'
idx = 0

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
        a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        """
        try:
>           obj, end = self.scan_once(s, idx)
E           json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 15727 (char 15726)

/usr/lib/python3.6/json/decoder.py:355: JSONDecodeError
lukas-bednar commented 5 years ago

it looks to me like some encoding issue

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 15727 (char 15726)
In [1]: chr(15726)
Out[1]: '㵮'

Are you able to get that json dump which causes this issue ?

gs202 commented 5 years ago

Unfortunately not, this happened only once during a Jenkins job which isn't available anymore

gs202 commented 5 years ago

@lukas-bednar i can see that the json is missing "]}}}" at the end, not sure why it happens, but setting a retry on that call returned with a valid json. I prefer not to share the dump, as it contains company data

gs202 commented 5 years ago

fixed with merged PR