Open antoine-gallix opened 6 years ago
I've been having this same problem on Flask-Restless==0.17.0
. I don't know if this is the correct way to solve this, but putting create_api
with the app
keyword argument inside an application context seemed to work for me:
def create_app():
app = Flask(__name__)
db.init_app(app)
api.init_app(app, flask_sqlalchemy_db=db)
with app.app_context():
api.create_api(Thing, methods=['GET', 'POST'], app=app)
return app
Though I'm able to test my application I'd still like to know the real cause of this issue.
It seems to be the same issue found earlier: https://github.com/jfinkels/flask-restless/issues/409
TL;DR: Workaround i'm using right now:
db = SQLAlchemy()
def create_app():
...
db.app = app
db.init_app(app)
After struggling with this problem in my application, I managed to recreate the smallest application that triggers this error. The smallest application using flask restless I could think about is this one:
It works. Now I want to use an application factory pattern. I want to handle models in one file, api blueprints in another, and create my application in a function. I refactor the previous application into this:
I get the following error:
Strangely, this only happens when I want to use the POST method, not when only using GET