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

Jinja templating seems to be crashing PyStack with an IndexError #191

Open
1 task done
strugee opened this issue Jul 1, 2024 · 1 comment
Open
1 task done

Jinja templating seems to be crashing PyStack with an IndexError #191

strugee opened this issue Jul 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@strugee
Copy link

strugee commented Jul 1, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

<irrelevant stack trace output truncated>
    (Python) File "/opt/venvs/debtsy/lib/python3.9/site-packages/flask/templating.py", line 120, in _render
        rv = template.render(context)
    (Python) File "/opt/venvs/debtsy/lib/python3.9/site-packages/ddtrace/contrib/jinja2/patch.py", line 70, in _wrap_render
        return wrapped(*args, **kwargs)
    (Python) File "/opt/venvs/debtsy/lib/python3.9/site-packages/jinja2/environment.py", line 1043, in render
        return concat(self.root_render_func(self.new_context(vars)))
    (Python) File "/opt/venvs/debtsy/lib/python3.9/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 24, in root
        {%- if admin_view.can_view_details -%}
    (Python) File "/opt/venvs/debtsy/lib/python3.9/site-packages/flask_admin/templates/bootstrap3/admin/master.html", line 16, in root
Traceback (most recent call last):
  File "/root/venv/bin/pystack", line 8, in <module>
    sys.exit(main())
  File "/root/venv/lib/python3.8/site-packages/pystack/__main__.py", line 254, in main
    args.func(parser, args)
  File "/root/venv/lib/python3.8/site-packages/pystack/__main__.py", line 381, in process_core
    print_thread(thread, native)
  File "/root/venv/lib/python3.8/site-packages/pystack/traceback_formatter.py", line 15, in print_thread
    for line in format_thread(thread, native):
  File "/root/venv/lib/python3.8/site-packages/pystack/traceback_formatter.py", line 81, in format_thread
    yield from format_frame(current_frame)
  File "/root/venv/lib/python3.8/site-packages/pystack/traceback_formatter.py", line 29, in format_frame
    source = lines[code.location.lineno - 1]
IndexError: list index out of range

Expected Behavior

PyStack does not crash when processing this process.

Steps To Reproduce

I can try and nail down a more constrained STR, but I'm not really sure what to actually try since that it's hard to reduce our entire app to a minimal example... given the traceback (see below), I figured I would file a bug and see if anyone had any ideas on what to try based on their knowledge of the way PyStack works.

PyStack was freshly installed from Pip FWIW, into a fresh virtual environment. This crash happened on both a coredump file and on a live process (processing a request for the same URL). We're running Ubuntu 20.04.6.

Pystack Version

1.3.0

Python Version

3.8

Linux distribution

Ubuntu

Anything else?

No response

@strugee strugee added the bug Something isn't working label Jul 1, 2024
@pablogsal
Copy link
Member

pablogsal commented Jul 2, 2024

Hi @strugee and thanks for the report! We can try to investigate but without a reproducer is very hard for us to do anything here. Can you try to get a small jinja-based example to see if it crashes?

if not, can you modify /root/venv/lib/python3.8/site-packages/pystack/traceback_formatter.py to print lines and code.location? Like so:

print(lines, code.location)
source = lines[code.location.lineno - 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants