Skip to content

Commit b5b3040

Browse files
authored
Forbid changing frozen app properties (#3948)
1 parent c6e40e7 commit b5b3040

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

CHANGES/3948.removal

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Forbid changing frozen app properties.

aiohttp/web_app.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ def __getitem__(self, key: str) -> Any:
125125

126126
def _check_frozen(self) -> None:
127127
if self._frozen:
128-
warnings.warn("Changing state of started or joined "
129-
"application is deprecated",
130-
DeprecationWarning,
131-
stacklevel=3)
128+
raise RuntimeError("Changing state of started or joined "
129+
"application is forbidden")
132130

133131
def __setitem__(self, key: str, value: Any) -> None:
134132
self._check_frozen()

tests/test_pytest_plugin.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,6 @@ def cli(loop, aiohttp_client):
8383
return loop.run_until_complete(aiohttp_client(create_stateful_app()))
8484
8585
86-
async def test_set_value(cli) -> None:
87-
resp = await cli.post('/', data={'value': 'foo'})
88-
assert resp.status == 200
89-
text = await resp.text()
90-
assert text == 'thanks for the data'
91-
assert cli.server.app['value'] == 'foo'
92-
93-
94-
async def test_get_value(cli) -> None:
95-
resp = await cli.get('/')
96-
assert resp.status == 200
97-
text = await resp.text()
98-
assert text == 'value: unknown'
99-
with pytest.warns(DeprecationWarning):
100-
cli.server.app['value'] = 'bar'
101-
resp = await cli.get('/')
102-
assert resp.status == 200
103-
text = await resp.text()
104-
assert text == 'value: bar'
105-
106-
10786
def test_noncoro() -> None:
10887
assert True
10988
@@ -137,7 +116,7 @@ async def test_custom_port_test_server(aiohttp_server, aiohttp_unused_port):
137116
""")
138117
testdir.makeconftest(CONFTEST)
139118
result = testdir.runpytest('-p', 'no:sugar', '--aiohttp-loop=pyloop')
140-
result.assert_outcomes(passed=10)
119+
result.assert_outcomes(passed=8)
141120

142121

143122
def test_warning_checks(testdir) -> None:

tests/test_web_app.py

+7
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,10 @@ def test_app_forbid_nonslot_attr():
450450
app.unknow_attr
451451
with pytest.raises(AttributeError):
452452
app.unknow_attr = 1
453+
454+
455+
def test_forbid_changing_frozen_app() -> None:
456+
app = web.Application()
457+
app.freeze()
458+
with pytest.raises(RuntimeError):
459+
app['key'] = 'value'

0 commit comments

Comments
 (0)