Skip to content

resources.py __getattr__ causing stack overflow #1721

Open
@sparrowt

Description

@sparrowt

Bug summary

In certain cirumstances jira.resources.Resource.__getattr__ enters an infinite loop resulting in stack overflow (see output below).

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

9.4.8 (though this is not relevant)

jira-python version

3.5.2 (latest as of today)

Python Interpreter version

3.8

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

  1. Set up a virtualenv and install the following
pip install jira==3.5.2 pytest==7.4.0
  1. Save this test as test_stuff.py
from unittest import mock

import jira
from requests.models import Response


def test_stuff():
    # Simulate a broken response
    duff_response = Response()
    duff_response.status_code = 200
    duff_response.reason = 'foo'
    duff_response._content = b'{"something":"blah"}'

    with mock.patch('jira.resilientsession.ResilientSession.get', return_value=duff_response):
        # Try to log in - this fails with stack overflow
        jira.JIRA(
            'https://jira.example.net',
            token_auth='thisisatoken',
            validate=True,
        )
  1. Run it e.g. py.test test_stuff.py and observe the unexpected stack overflow as below

Stack trace

Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x0000a32c (most recent call first):
  File "path\to\venv\lib\site-packages\jira\resources.py", line 222 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  File "path\to\venv\lib\site-packages\jira\resources.py", line 224 in __getattr__
  ...

Expected behaviour

No stack overflow, instead the test should fail in jira.resources.User.init with a sensible message

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions