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

Tweak detection of app factories #914

Merged
merged 1 commit into from
Dec 26, 2020
Merged

Conversation

florimondmanca
Copy link
Member

@florimondmanca florimondmanca commented Dec 26, 2020

Fixes #900, cleanup for #875, based on #900 (comment)

Instead of inspecting the app, attempt to call it without arguments each time.

  • When it fails without --factory, consider it as normal — the app is meant to be an app instance.
  • When it fails with --factory, exit with an error message — the factory failed to load.
  • When it succeeds without --factory, keep Uvicorn running, but issue a warning — explicit flag is preferred:
$ uvicorn debug.app:create_app
WARNING:  ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly.
INFO:     Started server process [202]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

This removes the inspect.signature code that was causing getsentry/sentry-python#947.

@euri10
Copy link
Member

euri10 commented Dec 26, 2020

this rocks !

@florimondmanca florimondmanca merged commit afb2d56 into master Dec 26, 2020
@florimondmanca florimondmanca deleted the fm/factory-inspection branch December 26, 2020 15:36
@kristjanvalur
Copy link
Contributor

Great, thanks!

@florimondmanca florimondmanca mentioned this pull request Dec 29, 2020
ion-oset added a commit to ion-oset/electorate-vanadium-core that referenced this pull request Jan 13, 2022
- Add help for 'make serve-test', clarifying that it enables reloads.
- Add '--factory' flag to silence warning:

    ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly.

  See:
    - https://www.uvicorn.org/#application-factories
    - encode/uvicorn#875
    - encode/uvicorn#914
ion-oset added a commit to TrustTheVote-Project/Electorate-Vanadium-Core that referenced this pull request Feb 8, 2022
- Add help for 'make serve-test', clarifying that it enables reloads.
- Add '--factory' flag to silence warning:

    ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly.

  See:
    - https://www.uvicorn.org/#application-factories
    - encode/uvicorn#875
    - encode/uvicorn#914
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uvirorn.workers.UvicornWorker fails with certain ASGI middleware
3 participants