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

3.0.{0,1}: SystemError: <built-in function _escape_inner> returned NULL without setting an exception #473

Closed
ervandew opened this issue Oct 10, 2024 · 1 comment

Comments

@ervandew
Copy link

ervandew commented Oct 10, 2024

We are using markupsafe within a jinja2 environment, and ran into an issue not present in 2.1.5, but occurs in 3.0.0 and 3.0.1, running on python 3.12.6 and python 3.12.7:

Traceback (most recent call last):
  File "markupsafe_error.py", line 9, in <module>
    result = env.from_string('{{ value }}').render({'value': Something()})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "lib/python3.12/site-packages/markupsafe/__init__.py", line 45, in escape
    return Markup(_escape_inner(str(s)))
                  ^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in function _escape_inner> returned NULL without setting an exception

It occurs when attempting to evaluate the result of escape in a jinja template coming from the __str__ of an object, when the jinja environment has autoescape set to True. I realize this is redundant (having autoescape + using escape), but this is in an older code base where tracking down all redundant uses is not ideal and does look to be a regression from 2.1.5 which does not produce an error.

from jinja2 import Environment
from markupsafe import escape

class Something:
  def __str__(self):
    return escape('something')

env = Environment(autoescape=True)
env.from_string('{{ value }}').render({'value': Something()})

Environment:

  • Python version: 3.12.6 and 3.12.7
  • MarkupSafe version: 3.0.0 and 3.0.1

I'm guessing one of the recent refactorings to the c code may have introduced this regression:
#434
#437

@davidism
Copy link
Member

Duplicate of #472

@davidism davidism marked this as a duplicate of #472 Oct 10, 2024
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