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 server not working with uvicorn reload option enabled #1923

Open
kakuche opened this issue May 7, 2024 · 0 comments
Open

FlaskApp server not working with uvicorn reload option enabled #1923

kakuche opened this issue May 7, 2024 · 0 comments

Comments

@kakuche
Copy link

kakuche commented May 7, 2024

Description

When trying to run a development server for a Flask api the uvicorn reloader appears to duplicate the api route definitions, causing the error shown below. The server runs normally as long as the automatic reloader is disabled.

Since this is my first attempt at api development there's a good chance I simply missed some necessary settings, so any feedback is appreciated.

Expected behaviour

Update of the development server on code changes to .py files.

Actual behaviour

Running the development server with uvicorn and reload=True argument causes the following error on startup:

AssertionError: View function mapping is overwriting an existing endpoint function: index

This triggers either on the first route defined with an @app.route() decorator, or the server url in the openapi specification when no additional routes are defined with the decorator.

Steps to reproduce

install connexion with pip install connexion[flask,uvicorn,swagger-ui]

create app as follows and attempt to run

import pathlib
from connexion import App

basedir = pathlib.Path(__file__).parent.resolve()
app = App(__name__, specification_dir=basedir)
app.add_api(basedir / "openapi.yml")

@app.route("/")
def index():
    return "something"

if __name__ == "__main__":

    app.run(f"{Path(__file__).stem}:app", host="127.0.0.1", port=8000, reload=True)

Additional info:

Output of the commands:

  • python --version: Python 3.11.5
  • pip show connexion | grep "^Version\:": Version 3.0.6
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

1 participant