Skip to content

MarkupSafe 3.0.0 throws when used with SimpleLazyObjects #467

@dhendo

Description

@dhendo

If you attempt to escape a SimpleLazyObject using Markup.escape, it will throw as below. Confirmed working in MarkupSafe 2.1.5.

from django.utils.functional import SimpleLazyObject
from markupsafe import Markup

a = "Normal String"
b = SimpleLazyObject( lambda: "Lazy String")

print(a)
print(b)

print(Markup.escape(a))
print(Markup.escape(b))

Output:

Normal String
Lazy String
Normal String
Traceback (most recent call last):
  File "/snap/pycharm-professional/418/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "/snap/pycharm-professional/418/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/pycharm-professional/418/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/davidh/dev/TriggeredMessagingV1/test.py", line 11, in <module>
    print(Markup.escape(b))
          ^^^^^^^^^^^^^^^^
  File "python3.11/site-packages/markupsafe/__init__.py", line 233, in escape
    rv = escape(s)
         ^^^^^^^^^
  File "python3.11/site-packages/markupsafe/__init__.py", line 38, in escape
    return Markup(_escape_inner(s))
                  ^^^^^^^^^^^^^^^^
SystemError: <built-in function _escape_inner> returned NULL without setting an exception

Environment:

  • Python version: 3.11.8
  • MarkupSafe version: 3.0.0
  • Jinja2: 3.1.2, 3.1.4
  • Django: 3.2.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions