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

Upgrade to connexion 3.0+ #1370

Open
ahal opened this issue Nov 7, 2023 · 6 comments
Open

Upgrade to connexion 3.0+ #1370

ahal opened this issue Nov 7, 2023 · 6 comments

Comments

@ahal
Copy link
Contributor

ahal commented Nov 7, 2023

In #1369 I pinned connexion < 3.0 because it causes test failures. It turns out that connexion 3.0 is a major re-write of the library:
https://connexion.readthedocs.io/en/latest/v3.html

I didn't have time to figure out how to upgrade, so just added a pin for now. Note I didn't look into it at all, so upgrading could be quite easy, I'm not sure.

@JohanLorenzo
Copy link
Contributor

I spent an hour looking into this yesterday. It looks like a rabbit hole. I didn't manage to green up tox. I'll put one comment per errore I encountered with tox.

@JohanLorenzo
Copy link
Contributor

1. Easy: Fix src/backend_common/api.py:10: ModuleNotFoundError

>   from connexion.apis.flask_api import FlaskApi
E   ModuleNotFoundError: No module named 'connexion.apis'

src/backend_common/api.py:10: ModuleNotFoundError

This patch does the trick (source: spec-first/connexion#1621):

-from connexion.apis.flask_api import FlaskApi
+from connexion.apps.flask import FlaskApi

@JohanLorenzo
Copy link
Contributor

JohanLorenzo commented Feb 7, 2024

2. Easy: .tox/py39/lib/python3.9/site-packages/connexion/apps/flask.py:11: ModuleNotFoundError

>   from a2wsgi import WSGIMiddleware
E   ModuleNotFoundError: No module named 'a2wsgi'

.tox/py39/lib/python3.9/site-packages/connexion/apps/flask.py:11: ModuleNotFoundError

Made it work with:

-connexion = {version = "*", extras = ["swagger-ui"]}
+connexion = {version = "*", extras = ["swagger-ui", "flask"]}

This seems to be an extra thing now because connexion 3.0 switched to an ASGI server instead of a WSGI server (source: https://connexion.readthedocs.io/en/stable/v3.html#running-the-application)

@JohanLorenzo
Copy link
Contributor

3. Easy: .tox/py39/lib/python3.9/site-packages/connexion/middleware/abstract.py:60: AttributeError

    def _set_base_path(self, base_path: t.Optional[str] = None) -> None:
        if base_path is not None:
            # update spec to include user-provided base_path
            self.specification.base_path = base_path
            self.base_path = base_path
        else:
>           self.base_path = self.specification.base_path
E           AttributeError: 'PosixPath' object has no attribute 'base_path'

.tox/py39/lib/python3.9/site-packages/connexion/middleware/abstract.py:60: AttributeError

Made it work with:

+from connexion.spec import Specification
[...]
-            specification=pathlib.Path(specification),
+            specification=Specification.from_file(specification),

@JohanLorenzo
Copy link
Contributor

4. Unsure if I got the right fix: src/backend_common/api.py:98: AttributeError

>       self.swagger_url = api.options.openapi_console_ui_path
E       AttributeError: 'FlaskApi' object has no attribute 'options'

src/backend_common/api.py:98: AttributeError

I'm not sure of the impact of:

+++ b/api/src/backend_common/api.py

-        self.swagger_url = api.options.openapi_console_ui_path

@JohanLorenzo
Copy link
Contributor

5. Couldn't fix it: .tox/py39/lib/python3.9/site-packages/werkzeug/local.py:508: RuntimeError

    def _get_current_object() -> T:
        try:
            obj = local.get()
        except LookupError:
>           raise RuntimeError(unbound_message) from None
E           RuntimeError: Working outside of operation context. Make sure your app is wrapped in a ContextMiddleware and you're processing a request while accessing the context.

.tox/py39/lib/python3.9/site-packages/werkzeug/local.py:508: RuntimeError

This issue seems not to be specific to connexion only. It's more of a flask thing:

This week is RelEng's meet-up on taskgraph. I don't think I'll have enough time to upgrade connexion this week. That's why I posted my progress for posterity.

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

No branches or pull requests

2 participants