Skip to content

HTTPException.description can no longer be None in werkzeug 2.x. #2115

Closed
@mhaas

Description

@mhaas

The werkzeug HTTPException class has a description property, which is allowed to be None according to type hints.

In werkzeug 1.x, this worked fine. In werkzeug 2.x, having description set to None leads to an exception:

Python 3.7.5 (v3.7.5:5c02a39a0b, Oct 14 2019, 18:49:57) 
[Clang 6.0 (clang-600.0.57)] on darwin
from werkzeug.exceptions import HTTPException
e = HTTPException()
e.get_description()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/d073668/work/ml/meh/ML-MEH-Commons/venv/lib/python3.7/site-packages/werkzeug/exceptions.py", line 158, in get_description
    description = escape(self.description).replace("\n", "<br>")  # type: ignore
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/html/__init__.py", line 19, in escape
    s = s.replace("&", "&amp;") # Must be done first!
AttributeError: 'NoneType' object has no attribute 'replace'

I believe this error is happening because the escape function used in HTTPException.get_description has been replaced. In Werkzeug 1.x, this was werkzeug.utils.escape which replaces None with the empty string"". In werkzeug 2.x, this is now coming from Python's built-in html package, which does not handle None.

Environment:

  • Python version: 3.7.5
  • Werkzeug version: 2.0.0 (broken)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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