question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to run app from app factory?

See original GitHub issue

I try to run the server by command uvicorn my_packege.app:create_app and got error: TypeError: __call__() missing 1 required positional argument: 'send'. What could be the reason?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
kristjanvalurcommented, Oct 13, 2020

application factories were added to flask due to the need to not having application creation a side effect of importing modules. It also allows having different versions/configurations of applications existing at the same time, which is great for unit tests. This pattern extends further, in that settings are typically stored as an object on the application itself, rather than statics in a settings module. Different settings can thus be created for different purposes, without having to restart the entire process. I am a bit surprised that this kind of pattern isn’t encouraged and supported by starlette / uvicorn, since it evolved as a response to a need.

8reactions
heckadcommented, Dec 4, 2019

I’m curious where the intent is coming from here, since Gunicorn doesn’t use an “app factory” style either. Is there a particular Python framework / server that you’re comparing this too?

flask, aiohttp

(I’m not totally against us having an invocation like that, but it’s not expected usage, and it’s not obvious that it’s required)

Factory need when you need test the app. If you use a global app then you get one app but in unit tests need to create an app for each test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application Factories — Flask Documentation (2.2.x)
Testing. You can have instances of the application with different settings to test every case. · Multiple instances. Imagine you want to run...
Read more >
Demystifying Flask's “Application Factory”
Separating logic between modules means we'd be importing this app object all over the place, eventually leading to problems like circular imports. The...
Read more >
How to set up a production-grade flask application using ...
The function where the instantiation of the flask app is defined is called an application factory function (because it is literary used to ......
Read more >
Configure Python Flask App to use "create_app" factory and ...
I've started migrating toward using the form of the create_app pattern that Miguel Grinberg introduces in part XV of his Flask Mega-Tutorial ...
Read more >
Setting up App Factory - Pega Academy
Once your Pega Platform environments are acquired, it is time to install the App Factory component. Download the installation guide accessible from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found