-
Notifications
You must be signed in to change notification settings - Fork 4
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
flask-shell-bpython interferes with flask-sqlalchemy inside flask shell #13
Comments
Thanks for the report! I see something different, a loud error: >>> from app.models import Employee, db
>>> employee = Employee('[email protected]', 'password')
>>> db.session.add(employee)
Traceback (most recent call last):
File "<input>", line 1, in <module>
db.session.add(employee)
File "/home/jacquerie/.envs/contoso-ace/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", lin
e 153, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/jacquerie/.envs/contoso-ace/lib/python3.6/site-packages/sqlalchemy/util/_collections.py
", line 1001, in __call__
return self.registry.setdefault(key, self.createfunc())
File "/home/jacquerie/.envs/contoso-ace/lib/python3.6/site-packages/sqlalchemy/orm/session.py", lin
e 3010, in __call__
return self.class_(**local_kw)
File "/home/jacquerie/.envs/contoso-ace/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py",
line 141, in __init__
self.app = app = db.get_app()
File "/home/jacquerie/.envs/contoso-ace/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py",
line 912, in get_app
'No application found. Either work inside a view function or push'
RuntimeError: No application found. Either work inside a view function or push an application context
. See http://flask-sqlalchemy.pocoo.org/contexts/. In order to make it work I have to push an application context on the stack myself (which shouldn't be the case, so something is broken): >>> with app.app_context():
... employee = Employee('[email protected]', 'password')
... db.session.add(employee)
... db.session.commit()
>>> Can you share a simplified version of your application? I'd like to reproduce the same (lack of) error... |
hi! Sorry, I totally forgot about this. Meanwhile my app has grown significantly, and I now have the same problem as you are experiencing. Big fat error first and everything working as expected after pushing the application context. Strange... :-/ |
1 similar comment
hi! Sorry, I totally forgot about this. Meanwhile my app has grown significantly, and I now have the same problem as you are experiencing. Big fat error first and everything working as expected after pushing the application context. Strange... :-/ |
Sorry, maybe I should keep it open? My personal issue seems to have vanished, but of course the fact that the application context is not getting pushed of course goes against the Flask documentation of |
Same issue here: RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/. No idea why though 😞 |
Same issue here. Here's the traceback I got (analogous to @jacquerie's above): >>> from factories import UserFactory
>>> from app import db
>>> users = UserFactory.create_batch(10)
>>> db.session.add_all(users) # error
Traceback (most recent call last):
File "<input>", line 1, in <module>
db.session.add_all(users)
File "/home/foo/venvs/venv_1/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 162, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/foo/venvs/venv_1/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 1032, in __call__
return self.registry.setdefault(key, self.createfunc())
File "/home/foo/venvs/venv_1/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 3234, in __call__
return self.class_(**local_kw)
File "/home/foo/venvs/venv_1/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 136, in __init__
self.app = app = db.get_app()
File "/home/foo/venvs/venv_1/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 982, in get_app
'No application found. Either work inside a view function or push' The >>> with app.app_context():
... users = UserFactory.create_batch(10)
... db.session.add_all(users) # no error
... db.session.commit()
...
>>> For comparison, here's a working example using the normal Flask shell: >>> from factories import UserFactory
>>> from app import db
>>> user = UserFactory.create()
>>> db.session.add(user) # no error
>>> db.session.commit() |
Please have a look at my Stackoverflow question at https://stackoverflow.com/questions/54268271/sqlalchemy-db-session-commit-behaviour. I'll copy paste it here as reference too:
The text was updated successfully, but these errors were encountered: