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

FlaskApp context issue #1824

Closed
BoldizsarP opened this issue Dec 2, 2023 · 6 comments · Fixed by #1833
Closed

FlaskApp context issue #1824

BoldizsarP opened this issue Dec 2, 2023 · 6 comments · Fixed by #1833

Comments

@BoldizsarP
Copy link

Description

I am using connexion as the API handler for a webapp that runs via the included flask app. If I am using 2.0, my stack, consisting of

native flask syntax
(Mind you app is FlaskApp.app)
...
@app.route("/")
def index():
return redirect("/app")
...

and connexion+openapi3.0 syntax

works as expected.

Expected behaviour

The underlying flask app serves all the html file requests, while the openapi specifications are handling the api endpoints.

Actual behaviour

I get this issue for the endpoints:
ERROR:connexion.middleware.exceptions: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.")

Steps to reproduce

I have included the app,py
a sample openapi yaml, and the corresponding endpoint handler file.

The api file should be under ./api

the openapi should be under ./swagger

the app.py should be in top of relative path

Additional info:

It works flawlessly in 2.0, if I just downgrade it works

Output of the commands:

Thanks guys!

@ThomasSchwengler
Copy link

Hey, which version of starlette are you using?

I noticed today that my test cases are failing with the same error message when using starlette 0.33.0. With 0.32.0.post1 everything works as expected.

@BoldizsarP
Copy link
Author

Exactly! I am using pipenv, explicitly installing starlette<=0.32.0.post1 made it work!

Thanks for the help!

@cybertiger
Copy link

Could we not close this issue yet?

I am also having problems with starlette 0.33.0 breaking unit tests and have had to pin it to 0.32.0-post1 also.

Pinning dependencies is a workaround, not a resolution.

@BoldizsarP BoldizsarP reopened this Dec 5, 2023
@BoldizsarP
Copy link
Author

Reoppening until issue with starlette 0.33.0 is resolved

@nielsbox
Copy link
Collaborator

nielsbox commented Dec 6, 2023

@BoldizsarP in #1828 and Connexion 3.0.4 we have pinned starlette to <0.33.0. So no additional pinning is needed for now until encode/starlette#2361 is resolved. Ref: #1826

@agherasim
Copy link

+1 on encountering this issue with connexion and base_path / openapi servers configuration.

ERROR:root:Working outside of operation context. Make sure your app is wrapped in a ContextMiddleware and you're processing a request while accessing the context.

Using connexion 3.0.4 or downgrading starlette to <0.33.0 solves the issue.

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

Successfully merging a pull request may close this issue.

5 participants