diff options
author | Joris Hartog <jorishartog@hotmail.com> | 2021-12-03 15:01:18 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2022-02-02 13:25:05 +0100 |
commit | 72f6a4b9ba25c3627dbff44a2768f4f49f0ae222 (patch) | |
tree | eaa9efa3745f9f612478b2c999d8dd553f2d0b24 | |
parent | b7a03a60f1d497009bc303d2f90b80b39c68dbf3 (diff) | |
download | bottle-72f6a4b9ba25c3627dbff44a2768f4f49f0ae222.tar.gz |
Fix #1359: check for attribute using hasattr
This commit fixes a bug where setting an existing, read-only property
of a BaseRequest object does not raise an AttributeError.
Fixes #1359
-rwxr-xr-x | bottle.py | 2 | ||||
-rwxr-xr-x | test/test_environ.py | 3 |
2 files changed, 4 insertions, 1 deletions
@@ -1594,7 +1594,7 @@ class BaseRequest(object): def __setattr__(self, name, value): if name == 'environ': return object.__setattr__(self, name, value) key = 'bottle.request.ext.%s' % name - if key in self.environ: + if hasattr(self, name): raise AttributeError("Attribute already defined: %s" % name) self.environ[key] = value diff --git a/test/test_environ.py b/test/test_environ.py index 908b9d8..d367448 100755 --- a/test/test_environ.py +++ b/test/test_environ.py @@ -462,6 +462,9 @@ class TestRequest(unittest.TestCase): # Attributes are read-only once set. self.assertRaises(AttributeError, setattr, r, 'foo', 'x') + # Properties raise AttributeError. + self.assertRaises(AttributeError, setattr, r, 'body', 'x') + # Unknown attributes raise AttributeError. self.assertRaises(AttributeError, getattr, r, 'somevalue') |