From 9d5093db4b9a12486ff2911bf59eff3b284d4b4df62c50b23ac0047240af086f Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Wed, 8 Sep 2021 22:24:41 +0000 Subject: [PATCH 1/3] - Add python39-failures.patch to fix test problems with Python 3.9.7+ (gh#aio-libs/aiohttp#5991). OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-aiohttp?expand=0&rev=68 --- python-aiohttp.changes | 6 ++++ python-aiohttp.spec | 3 ++ python39-failures.patch | 77 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 python39-failures.patch diff --git a/python-aiohttp.changes b/python-aiohttp.changes index f310e02..6c0bed7 100644 --- a/python-aiohttp.changes +++ b/python-aiohttp.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Sep 8 21:10:23 UTC 2021 - Matej Cepl + +- Add python39-failures.patch to fix test problems with Python 3.9.7+ + (gh#aio-libs/aiohttp#5991). + ------------------------------------------------------------------- Tue Jun 8 19:15:11 UTC 2021 - Matej Cepl diff --git a/python-aiohttp.spec b/python-aiohttp.spec index 60aa571..3425bda 100644 --- a/python-aiohttp.spec +++ b/python-aiohttp.spec @@ -29,6 +29,9 @@ Patch0: unbundle-http-parser.patch # PATCH-FIX-UPSTREAM stdlib-typing_extensions.patch gh#aio-libs/aiohttp#5374 mcepl@suse.com # Fix typing_extensions imports. Patch1: stdlib-typing_extensions.patch +# PATCH-FIX-UPSTREAM python39-failures.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com +# Test problems Python 3.9.7+ +Patch2: python39-failures.patch BuildRequires: %{python_module Cython} BuildRequires: %{python_module async_timeout >= 3.0} BuildRequires: %{python_module attrs >= 17.3.0} diff --git a/python39-failures.patch b/python39-failures.patch new file mode 100644 index 0000000..6f21314 --- /dev/null +++ b/python39-failures.patch @@ -0,0 +1,77 @@ +--- + tests/test_web_middleware.py | 27 ++++++++++++++++++++++----- + 1 file changed, 22 insertions(+), 5 deletions(-) + +--- a/tests/test_web_middleware.py ++++ b/tests/test_web_middleware.py +@@ -1,4 +1,5 @@ + import re ++import sys + from typing import Any + + import pytest +@@ -6,6 +7,7 @@ from yarl import URL + + from aiohttp import web + ++py39 = sys.version_info[:3] >= (3, 9, 7) + + async def test_middleware_modifies_response(loop, aiohttp_client) -> None: + async def handler(request): +@@ -410,7 +412,10 @@ async def test_old_style_middleware(loop + txt = await resp.text() + assert "OK[old style middleware]" == txt + +- assert len(warning_checker) == 1 ++ if py39: ++ assert len(warning_checker) == 2 ++ else: ++ assert len(warning_checker) == 1 + msg = str(warning_checker.list[0].message) + assert re.match( + "^old-style middleware " +@@ -464,7 +469,10 @@ async def test_mixed_middleware(loop, ai + txt = await resp.text() + assert "OK[new style 2][old style 2][new style 1][old style 1]" == txt + +- assert len(w) == 2 ++ if py39: ++ assert len(w) == 3 ++ else: ++ assert len(w) == 2 + tmpl = ( + "^old-style middleware " + '".' +@@ -503,7 +511,10 @@ async def test_old_style_middleware_clas + txt = await resp.text() + assert "OK[old style middleware]" == txt + +- assert len(warning_checker) == 1 ++ if py39: ++ assert len(warning_checker) == 2 ++ else: ++ assert len(warning_checker) == 1 + msg = str(warning_checker.list[0].message) + assert re.match( + "^old-style middleware " +@@ -537,7 +548,10 @@ async def test_new_style_middleware_clas + txt = await resp.text() + assert "OK[new style middleware]" == txt + +- assert len(warning_checker) == 0 ++ if py39: ++ assert len(warning_checker) == 1 ++ else: ++ assert len(warning_checker) == 0 + + + async def test_new_style_middleware_method(loop, aiohttp_client) -> None: +@@ -563,4 +577,7 @@ async def test_new_style_middleware_meth + txt = await resp.text() + assert "OK[new style middleware]" == txt + +- assert len(warning_checker) == 0 ++ if py39: ++ assert len(warning_checker) == 1 ++ else: ++ assert len(warning_checker) == 0 From 09aa0c64223b3b1c968968c4b9d99d5792eca48ecb0bf55fe03a644e44363f9c Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Thu, 9 Sep 2021 20:07:49 +0000 Subject: [PATCH 2/3] - Remove python39-failures.patch and replace it with actual fix of the issue in remove_deprecated_loop_argument.patch. - Add backport_fix_for_setting_cookies.patch for backport of fixes from 3.8 branch. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-aiohttp?expand=0&rev=69 --- backport_fix_for_setting_cookies.patch | 93 ++++++++++++++++++++++++++ python-aiohttp.changes | 8 +++ python-aiohttp.spec | 9 ++- python39-failures.patch | 77 --------------------- remove_deprecated_loop_argument.patch | 59 ++++++++++++++++ 5 files changed, 166 insertions(+), 80 deletions(-) create mode 100644 backport_fix_for_setting_cookies.patch delete mode 100644 python39-failures.patch create mode 100644 remove_deprecated_loop_argument.patch diff --git a/backport_fix_for_setting_cookies.patch b/backport_fix_for_setting_cookies.patch new file mode 100644 index 0000000..de94d94 --- /dev/null +++ b/backport_fix_for_setting_cookies.patch @@ -0,0 +1,93 @@ +From d0453ed56820e32802be743bf7a7b7027f9c9589 Mon Sep 17 00:00:00 2001 +From: Sam Bull +Date: Sat, 14 Nov 2020 15:24:43 +0000 +Subject: [PATCH 1/7] Backport fix for setting cookies + +--- + CHANGES/5233.bugfix | 1 + + aiohttp/web_protocol.py | 21 ++++++++++----------- + tests/test_web_exceptions.py | 28 ++++++++++++++++++++++++++++ + 3 files changed, 39 insertions(+), 11 deletions(-) + +--- /dev/null ++++ b/CHANGES/5233.bugfix +@@ -0,0 +1 @@ ++Fix cookies disappearing from HTTPExceptions. +--- a/aiohttp/web_protocol.py ++++ b/aiohttp/web_protocol.py +@@ -423,9 +423,7 @@ class RequestHandler(BaseProtocol): + finally: + self._current_request = None + except HTTPException as exc: +- resp = Response( +- status=exc.status, reason=exc.reason, text=exc.text, headers=exc.headers +- ) ++ resp = exc + reset = await self.finish_response(request, resp, start_time) + except asyncio.CancelledError: + raise +@@ -437,6 +435,15 @@ class RequestHandler(BaseProtocol): + resp = self.handle_error(request, 500, exc) + reset = await self.finish_response(request, resp, start_time) + else: ++ # Deprecation warning (See #2415) ++ if getattr(resp, "__http_exception__", False): ++ warnings.warn( ++ "returning HTTPException object is deprecated " ++ "(#2415) and will be removed, " ++ "please raise the exception instead", ++ DeprecationWarning, ++ ) ++ + reset = await self.finish_response(request, resp, start_time) + + return resp, reset +@@ -486,14 +493,6 @@ class RequestHandler(BaseProtocol): + except (asyncio.CancelledError, ConnectionError): + self.log_debug("Ignored premature client disconnection") + break +- # Deprecation warning (See #2415) +- if getattr(resp, "__http_exception__", False): +- warnings.warn( +- "returning HTTPException object is deprecated " +- "(#2415) and will be removed, " +- "please raise the exception instead", +- DeprecationWarning, +- ) + + # Drop the processed task from asyncio.Task.all_tasks() early + del task +--- a/tests/test_web_exceptions.py ++++ b/tests/test_web_exceptions.py +@@ -203,3 +203,31 @@ def test_HTTPException_retains_cause() - + tb = "".join(format_exception(ei.type, ei.value, ei.tb)) + assert "CustomException" in tb + assert "direct cause" in tb ++ ++ ++async def test_HTTPException_retains_cookie(aiohttp_client): ++ @web.middleware ++ async def middleware(request, handler): ++ try: ++ return await handler(request) ++ except web.HTTPException as exc: ++ exc.set_cookie("foo", request["foo"]) ++ raise exc ++ ++ async def save(request): ++ request["foo"] = "works" ++ raise web.HTTPFound("/show") ++ ++ async def show(request): ++ return web.Response(text=request.cookies["foo"]) ++ ++ app = web.Application(middlewares=[middleware]) ++ app.router.add_route("GET", "/save", save) ++ app.router.add_route("GET", "/show", show) ++ client = await aiohttp_client(app) ++ ++ resp = await client.get("/save") ++ assert resp.status == 200 ++ assert str(resp.url)[-5:] == "/show" ++ text = await resp.text() ++ assert text == "works" diff --git a/python-aiohttp.changes b/python-aiohttp.changes index 6c0bed7..9f484a2 100644 --- a/python-aiohttp.changes +++ b/python-aiohttp.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Thu Sep 9 20:05:44 UTC 2021 - Matej Cepl + +- Remove python39-failures.patch and replace it with actual fix + of the issue in remove_deprecated_loop_argument.patch. +- Add backport_fix_for_setting_cookies.patch for backport of + fixes from 3.8 branch. + ------------------------------------------------------------------- Wed Sep 8 21:10:23 UTC 2021 - Matej Cepl diff --git a/python-aiohttp.spec b/python-aiohttp.spec index 3425bda..f7abbc5 100644 --- a/python-aiohttp.spec +++ b/python-aiohttp.spec @@ -29,9 +29,12 @@ Patch0: unbundle-http-parser.patch # PATCH-FIX-UPSTREAM stdlib-typing_extensions.patch gh#aio-libs/aiohttp#5374 mcepl@suse.com # Fix typing_extensions imports. Patch1: stdlib-typing_extensions.patch -# PATCH-FIX-UPSTREAM python39-failures.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com -# Test problems Python 3.9.7+ -Patch2: python39-failures.patch +# PATCH-FIX-UPSTREAM remove_deprecated_loop_argument.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com +# remove deprecated loop argument +Patch2: remove_deprecated_loop_argument.patch +# PATCH-FIX-UPSTREAM backport_fix_for_setting_cookies.patch gh#aio-libs/aiohttp#5233 mcepl@suse.com +# backport of fixes from 3.8 branch +Patch3: backport_fix_for_setting_cookies.patch BuildRequires: %{python_module Cython} BuildRequires: %{python_module async_timeout >= 3.0} BuildRequires: %{python_module attrs >= 17.3.0} diff --git a/python39-failures.patch b/python39-failures.patch deleted file mode 100644 index 6f21314..0000000 --- a/python39-failures.patch +++ /dev/null @@ -1,77 +0,0 @@ ---- - tests/test_web_middleware.py | 27 ++++++++++++++++++++++----- - 1 file changed, 22 insertions(+), 5 deletions(-) - ---- a/tests/test_web_middleware.py -+++ b/tests/test_web_middleware.py -@@ -1,4 +1,5 @@ - import re -+import sys - from typing import Any - - import pytest -@@ -6,6 +7,7 @@ from yarl import URL - - from aiohttp import web - -+py39 = sys.version_info[:3] >= (3, 9, 7) - - async def test_middleware_modifies_response(loop, aiohttp_client) -> None: - async def handler(request): -@@ -410,7 +412,10 @@ async def test_old_style_middleware(loop - txt = await resp.text() - assert "OK[old style middleware]" == txt - -- assert len(warning_checker) == 1 -+ if py39: -+ assert len(warning_checker) == 2 -+ else: -+ assert len(warning_checker) == 1 - msg = str(warning_checker.list[0].message) - assert re.match( - "^old-style middleware " -@@ -464,7 +469,10 @@ async def test_mixed_middleware(loop, ai - txt = await resp.text() - assert "OK[new style 2][old style 2][new style 1][old style 1]" == txt - -- assert len(w) == 2 -+ if py39: -+ assert len(w) == 3 -+ else: -+ assert len(w) == 2 - tmpl = ( - "^old-style middleware " - '".' -@@ -503,7 +511,10 @@ async def test_old_style_middleware_clas - txt = await resp.text() - assert "OK[old style middleware]" == txt - -- assert len(warning_checker) == 1 -+ if py39: -+ assert len(warning_checker) == 2 -+ else: -+ assert len(warning_checker) == 1 - msg = str(warning_checker.list[0].message) - assert re.match( - "^old-style middleware " -@@ -537,7 +548,10 @@ async def test_new_style_middleware_clas - txt = await resp.text() - assert "OK[new style middleware]" == txt - -- assert len(warning_checker) == 0 -+ if py39: -+ assert len(warning_checker) == 1 -+ else: -+ assert len(warning_checker) == 0 - - - async def test_new_style_middleware_method(loop, aiohttp_client) -> None: -@@ -563,4 +577,7 @@ async def test_new_style_middleware_meth - txt = await resp.text() - assert "OK[new style middleware]" == txt - -- assert len(warning_checker) == 0 -+ if py39: -+ assert len(warning_checker) == 1 -+ else: -+ assert len(warning_checker) == 0 diff --git a/remove_deprecated_loop_argument.patch b/remove_deprecated_loop_argument.patch new file mode 100644 index 0000000..5a16a1d --- /dev/null +++ b/remove_deprecated_loop_argument.patch @@ -0,0 +1,59 @@ +From dd3a89130b5769218550159ebbab9e28d8b974a3 Mon Sep 17 00:00:00 2001 +From: Hanaasagi +Date: Tue, 3 Aug 2021 11:53:45 +0000 +Subject: [PATCH] fix: remove deprecated loop argument for asnycio.sleep/gather + calls + +--- + CHANGES/5905.bugfix | 1 + + aiohttp/web.py | 4 +--- + tests/test_locks.py | 6 +++--- + 3 files changed, 5 insertions(+), 6 deletions(-) + create mode 100644 CHANGES/5905.bugfix + +--- /dev/null ++++ b/CHANGES/5905.bugfix +@@ -0,0 +1 @@ ++remove deprecated loop argument for asnycio.sleep/gather calls +--- a/aiohttp/web.py ++++ b/aiohttp/web.py +@@ -440,9 +440,7 @@ def _cancel_tasks( + for task in to_cancel: + task.cancel() + +- loop.run_until_complete( +- asyncio.gather(*to_cancel, loop=loop, return_exceptions=True) +- ) ++ loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True)) + + for task in to_cancel: + if task.cancelled(): +--- a/tests/test_locks.py ++++ b/tests/test_locks.py +@@ -18,7 +18,7 @@ class TestEventResultOrError: + return 1 + + t = loop.create_task(c()) +- await asyncio.sleep(0, loop=loop) ++ await asyncio.sleep(0) + e = Exception() + ev.set(exc=e) + assert (await t) == e +@@ -31,7 +31,7 @@ class TestEventResultOrError: + return 1 + + t = loop.create_task(c()) +- await asyncio.sleep(0, loop=loop) ++ await asyncio.sleep(0) + ev.set() + assert (await t) == 1 + +@@ -43,7 +43,7 @@ class TestEventResultOrError: + + t1 = loop.create_task(c()) + t2 = loop.create_task(c()) +- await asyncio.sleep(0, loop=loop) ++ await asyncio.sleep(0) + ev.cancel() + ev.set() + From f541008472f2ca82947b31fb95f0537c7a28ae7989025cd5512df75d4ee821a9 Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Fri, 10 Sep 2021 14:23:03 +0000 Subject: [PATCH 3/3] - Restore python39-failures.patch, which is actually still needed. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-aiohttp?expand=0&rev=70 --- python-aiohttp.changes | 5 +++ python-aiohttp.spec | 7 ++-- python39-failures.patch | 77 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 python39-failures.patch diff --git a/python-aiohttp.changes b/python-aiohttp.changes index 9f484a2..1baeff3 100644 --- a/python-aiohttp.changes +++ b/python-aiohttp.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Sep 10 14:22:31 UTC 2021 - Matej Cepl + +- Restore python39-failures.patch, which is actually still needed. + ------------------------------------------------------------------- Thu Sep 9 20:05:44 UTC 2021 - Matej Cepl diff --git a/python-aiohttp.spec b/python-aiohttp.spec index f7abbc5..aba9a02 100644 --- a/python-aiohttp.spec +++ b/python-aiohttp.spec @@ -29,12 +29,15 @@ Patch0: unbundle-http-parser.patch # PATCH-FIX-UPSTREAM stdlib-typing_extensions.patch gh#aio-libs/aiohttp#5374 mcepl@suse.com # Fix typing_extensions imports. Patch1: stdlib-typing_extensions.patch +# PATCH-FIX-UPSTREAM python39-failures.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com +# Bridge over Python 3.9.6 v 3.9.7 incompatibilities +Patch2: python39-failures.patch # PATCH-FIX-UPSTREAM remove_deprecated_loop_argument.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com # remove deprecated loop argument -Patch2: remove_deprecated_loop_argument.patch +Patch3: remove_deprecated_loop_argument.patch # PATCH-FIX-UPSTREAM backport_fix_for_setting_cookies.patch gh#aio-libs/aiohttp#5233 mcepl@suse.com # backport of fixes from 3.8 branch -Patch3: backport_fix_for_setting_cookies.patch +Patch4: backport_fix_for_setting_cookies.patch BuildRequires: %{python_module Cython} BuildRequires: %{python_module async_timeout >= 3.0} BuildRequires: %{python_module attrs >= 17.3.0} diff --git a/python39-failures.patch b/python39-failures.patch new file mode 100644 index 0000000..6f21314 --- /dev/null +++ b/python39-failures.patch @@ -0,0 +1,77 @@ +--- + tests/test_web_middleware.py | 27 ++++++++++++++++++++++----- + 1 file changed, 22 insertions(+), 5 deletions(-) + +--- a/tests/test_web_middleware.py ++++ b/tests/test_web_middleware.py +@@ -1,4 +1,5 @@ + import re ++import sys + from typing import Any + + import pytest +@@ -6,6 +7,7 @@ from yarl import URL + + from aiohttp import web + ++py39 = sys.version_info[:3] >= (3, 9, 7) + + async def test_middleware_modifies_response(loop, aiohttp_client) -> None: + async def handler(request): +@@ -410,7 +412,10 @@ async def test_old_style_middleware(loop + txt = await resp.text() + assert "OK[old style middleware]" == txt + +- assert len(warning_checker) == 1 ++ if py39: ++ assert len(warning_checker) == 2 ++ else: ++ assert len(warning_checker) == 1 + msg = str(warning_checker.list[0].message) + assert re.match( + "^old-style middleware " +@@ -464,7 +469,10 @@ async def test_mixed_middleware(loop, ai + txt = await resp.text() + assert "OK[new style 2][old style 2][new style 1][old style 1]" == txt + +- assert len(w) == 2 ++ if py39: ++ assert len(w) == 3 ++ else: ++ assert len(w) == 2 + tmpl = ( + "^old-style middleware " + '".' +@@ -503,7 +511,10 @@ async def test_old_style_middleware_clas + txt = await resp.text() + assert "OK[old style middleware]" == txt + +- assert len(warning_checker) == 1 ++ if py39: ++ assert len(warning_checker) == 2 ++ else: ++ assert len(warning_checker) == 1 + msg = str(warning_checker.list[0].message) + assert re.match( + "^old-style middleware " +@@ -537,7 +548,10 @@ async def test_new_style_middleware_clas + txt = await resp.text() + assert "OK[new style middleware]" == txt + +- assert len(warning_checker) == 0 ++ if py39: ++ assert len(warning_checker) == 1 ++ else: ++ assert len(warning_checker) == 0 + + + async def test_new_style_middleware_method(loop, aiohttp_client) -> None: +@@ -563,4 +577,7 @@ async def test_new_style_middleware_meth + txt = await resp.text() + assert "OK[new style middleware]" == txt + +- assert len(warning_checker) == 0 ++ if py39: ++ assert len(warning_checker) == 1 ++ else: ++ assert len(warning_checker) == 0