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

resources.py __getattr__ causing stack overflow #1721

Open
2 of 4 tasks
sparrowt opened this issue Aug 25, 2023 · 2 comments · May be fixed by #1722
Open
2 of 4 tasks

resources.py __getattr__ causing stack overflow #1721

sparrowt opened this issue Aug 25, 2023 · 2 comments · May be fixed by #1722

Comments

@sparrowt
Copy link

sparrowt commented Aug 25, 2023

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

@sparrowt
Copy link
Author

If I put this at the start of resources.Resource.__getattr__ it avoids the issue:

        if item in ["raw"]:
            return self.__dict__[item]

@sparrowt sparrowt linked a pull request Aug 25, 2023 that will close this issue
@sparrowt
Copy link
Author

Proposed fix here: #1722

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 a pull request may close this issue.

1 participant