Skip to content

ResponseCacheControl.s_maxage raises error when set to an int #2364

@allanlei

Description

@allanlei

Response().cache_control.s_maxage errors with None is not callable

from werkzeug.datastructures import ResponseCacheControl

cc = ResponseCacheControl()
cc.s_maxage = 1

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [13], in <cell line: 1>()
----> 1 cc.s_maxage = 1

File /usr/local/lib/python3.10/site-packages/werkzeug/datastructures.py:1958, in cache_control_property.<locals>.<lambda>(x, v)
   1949 def cache_control_property(key, empty, type):
   1950     """Return a new property object for a cache header. Useful if you
   1951     want to add support for a cache extension in a subclass.
   1952 
   1953     .. versionchanged:: 2.0
   1954         Renamed from ``cache_property``.
   1955     """
   1956     return property(
   1957         lambda x: x._get_cache_value(key, empty, type),
-> 1958         lambda x, v: x._set_cache_value(key, v, type),
   1959         lambda x: x._del_cache_value(key),
   1960         f"accessor for {key!r}",
   1961     )

File /usr/local/lib/python3.10/site-packages/werkzeug/datastructures.py:2039, in _CacheControl._set_cache_value(self, key, value, type)
   2037     self[key] = None
   2038 else:
-> 2039     self[key] = type(value)

TypeError: 'NoneType' object is not callable

2.0.3 is OK

Flask use case

from flask import Response

response = Response()
response.cache_control.s_maxage = 1

Environment:

  • Python version: 3.10.4
  • Werkzeug version: 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions