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

crash with --spew #3344

Open
zogzog opened this issue Feb 4, 2025 · 3 comments
Open

crash with --spew #3344

zogzog opened this issue Feb 4, 2025 · 3 comments

Comments

@zogzog
Copy link

zogzog commented Feb 4, 2025

Verified with 20.0.4 and 23.0.0

The crash:

  File "/data/dev/miniconda3/lib/python3.12/site-packages/jsonschema/_format.py", line 11, in <module>
    from jsonschema.exceptions import FormatError
  File "/data/dev/miniconda3/lib/python3.12/site-packages/jsonschema/exceptions.py", line 14, in <module>
    from attrs import define
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attrs/__init__.py", line 3, in <module>
    from attr import (
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/__init__.py", line 10, in <module>
    from . import converters, exceptions, filters, setters, validators
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/converters.py", line 11, in <module>
    from ._make import NOTHING, Factory, pipe
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/_make.py", line 2458, in <module>
    _add_repr(Attribute, attrs=_a),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/_make.py", line 1695, in _add_repr
    cls.__repr__ = _make_repr(attrs, ns, cls)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/_make.py", line 1683, in _make_repr
    return _make_method(
           ^^^^^^^^^^^^^
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/_make.py", line 242, in _make_method
    _compile_and_eval(script, globs, locs, filename)
  File "/data/dev/miniconda3/lib/python3.12/site-packages/attr/_make.py", line 215, in _compile_and_eval
    eval(bytecode, globs, locs)
  File "<attrs generated repr attr._make.Attribute>", line 1, in <module>
    def __repr__(self):
  File "/data/dev/miniconda3/lib/python3.12/site-packages/gunicorn/debug.py", line 43, in __call__
    print('%s:%s: %s' % (name, lineno, line.rstrip()))
                                       ^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'rstrip'
@pajod
Copy link
Contributor

pajod commented Feb 4, 2025

Add context, please.
I am not aware of scenarios where the cPython builtins inspect or linecache ever pass non-strings. If you add yourself a few debug prints, you should be able to pinpoint invalid linecache overrides.. likely done by the attr(s) module visible in your trace.

@zogzog
Copy link
Author

zogzog commented Feb 4, 2025

I don't own the jsonschema stuff. I am reporting this because I think it may be useful. Maybe jsonschema is doing something nasty, I just don't know.

@pajod
Copy link
Contributor

pajod commented Feb 4, 2025

I am reasonably certain that gunicorns attempt at grabbing the source line https://github.com/benoitc/gunicorn/blob/4f77665/gunicorn/debug.py#L37-L38 is wrong. inspect.getsourcelines() returns tuple[list[str], int] and indexing that tuple by line number looks like a clear case of type confusion. If anything, the first element of that tuple should be indexed.

jsonschema just happens to insert new code, triggering but not causing the bug. At this time I cannot suggest a fix, because I still do not understand why the broken code went unnoticed before.

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

No branches or pull requests

2 participants