-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Milestone
Description
Setting response.cache_control.no_cache = False used to work up until version 2.0.x thanks to this code in datastructures.py, where the type value received is None:
def _set_cache_value(self, key, value, type):
"""Used internally by the accessor properties."""
if type is bool:
(...)
else:
if value is None:
self.pop(key, None)
elif value is True:
self[key] = None
else:
self[key] = value
Now it crashes because type is not checked for None in 2.1.x:
def _set_cache_value(self, key, value, type):
"""Used internally by the accessor properties."""
if type is bool:
(...)
else:
if value is None:
self.pop(key, None)
elif value is True:
self[key] = None
else:
self[key] = type(value) # <-- crashes if type is None
It type is None, this will crash:
TypeError: 'NoneType' object is not callable
I think the correct code should be:
def _set_cache_value(self, key, value, type):
"""Used internally by the accessor properties."""
if type is bool:
(...)
else:
if value is None:
self.pop(key, None)
elif value is True:
self[key] = None
elif type is None:
# do something, e.g. self[key] = value
else:
self[key] = type(value)
To reproduce:
def send_static(path):
response = send_from_directory('assets', path)
response.cache_control.no_cache = False
Expected behavior:
At least check for type being None before trying to call it and throw an appropriate exception if needed (not sure why it should be an error, the code worked fine in 2.0.3)
Environment:
- Python version: 3.10.x
- Werkzeug version: 2.1.1
Reactions are currently unavailable