Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after upgrading from 3.8.6 to 3.9.* can't use middlewares anymore #8137

Closed
1 task done
electronick opened this issue Feb 5, 2024 · 3 comments
Closed
1 task done
Labels

Comments

@electronick
Copy link

electronick commented Feb 5, 2024

Describe the bug

I'm using aoihttp with standard middlewares like this:

from aiohttp import web
from aiohttp_middlewares import error_middleware, https_middleware

async def make_app():
    app = web.Application(middlewares=[
        error_middleware(ignore_exceptions=web.HTTPFound),
        https_middleware(),
    ])

after upgrading aiohttp package from 3.8.6 to any of 3.9.* verions (tried all of them) I get an error:

ImportError: cannot import name '_Middleware' from 'aiohttp.web_middlewares' 

and can't start server anymore.

Would appreciate any information regarding what should I change in my code in order for it to work.

To Reproduce

Upgrade from 3.8.6 to 3.9.0, 3.9.1, 3.9.2 or 3.9.3

Expected behavior

I wan't able to find any upgrade notes, so I assumed that new version should work would any changes to the code.

Logs/tracebacks

Traceback (most recent call last):
  File "/Users/nick/work/deploy_server/start_aio.py", line 7, in <module>
    from aiohttp_middlewares import error_middleware, https_middleware
  File "/Users/nick/work/deploy_server/venv/lib/python3.10/site-packages/aiohttp_middlewares/__init__.py", line 14, in <module>
    from aiohttp_middlewares.cors import cors_middleware
  File "/Users/nick/work/deploy_server/venv/lib/python3.10/site-packages/aiohttp_middlewares/cors.py", line 122, in <module>
    from aiohttp_middlewares.annotations import (
  File "/Users/nick/work/deploy_server/venv/lib/python3.10/site-packages/aiohttp_middlewares/annotations.py", line 22, in <module>
    from aiohttp.web_middlewares import _Middleware as Middleware
ImportError: cannot import name '_Middleware' from 'aiohttp.web_middlewares' (/Users/nick/work/deploy_server/venv/lib/python3.10/site-packages/aiohttp/web_middlewares.py)


### Python Version

```console
$ venv/bin/python --version
Python 3.10.13

aiohttp Version

$ venv/bin/python -m pip show aiohttp
Name: aiohttp
Version: 3.9.3
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: /Users/nick/work/deploy_server/venv/lib/python3.10/site-packages
Requires: aiosignal, async-timeout, attrs, frozenlist, multidict, yarl
Required-by: aiogithubapi, aiohttp-middlewares, aiohttp-session, aiohttp_remotes, pytest-aiohttp

multidict Version

$ venv/bin/python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /Users/nick/work/deploy_server/venv/lib/python3.10/site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ venv/bin/python -m pip show yarl
Name: yarl
Version: 1.8.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /Users/nick/work/deploy_server/venv/lib/python3.10/site-packages
Requires: idna, multidict
Required-by: aiohttp, aiohttp-middlewares

OS

macOS 14.3

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@electronick electronick added the bug label Feb 5, 2024
@Dreamsorcerer
Copy link
Member

Yep, those are not the "standard" middlewares, they are a 3rd party package. If they've not released a fix, then you'll need to open an issue there.

Problem is that they were importing a private variable. We promoted that to a public variable to make it officially part of the API, so it can't find the private one anymore. As per the link above, it appears they've already updated the library to support 3.9+.

@Dreamsorcerer Dreamsorcerer closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
@electronick
Copy link
Author

Guys, thank you so much for your help! Indeed, the problem was connected to outdated aiohttp-middlewares package and I didn't notice that it's listed separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants