closeio / flask-mongorest

Restful API framework wrapped around MongoEngine
Other
522 stars 87 forks source link

Support delayed app initialization #137

Closed AlecRosenbaum closed 2 years ago

AlecRosenbaum commented 2 years ago

Closes https://github.com/closeio/flask-mongorest/issues/81

There's a workaround required here to support the decorator registration pattern exposed. Not all views are guaranteed to be imported/registered at the time init_app(app) is called. If MongoRest does not keep a running list of app objects it needs to register views to, none of those will actually be registered. So, this implements a delayed app class that just collects args/kwargs, then also collects a list of references to apps. Views are batch registered during init_app, then also registered to previously-initialized apps within MongoRest.register.