{"action":"opened","issue":{"url":"https://api.github.com/repos/davidhalter/jedi/issues/785","repository_url":"https://api.github.com/repos/davidhalter/jedi","labels_url":"https://api.github.com/repos/davidhalter/jedi/issues/785/labels{/name}","comments_url":"https://api.github.com/repos/davidhalter/jedi/issues/785/comments","events_url":"https://api.github.com/repos/davidhalter/jedi/issues/785/events","html_url":"https://github.com/davidhalter/jedi/issues/785","id":181956118,"number":785,"title":"RuntimeError when autocompleting Flask-SQLAlchemy queries","user":{"login":"jpvanhal","id":250983,"avatar_url":"https://avatars.githubusercontent.com/u/250983?v=3","gravatar_id":"","url":"https://api.github.com/users/jpvanhal","html_url":"https://github.com/jpvanhal","followers_url":"https://api.github.com/users/jpvanhal/followers","following_url":"https://api.github.com/users/jpvanhal/following{/other_user}","gists_url":"https://api.github.com/users/jpvanhal/gists{/gist_id}","starred_url":"https://api.github.com/users/jpvanhal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpvanhal/subscriptions","organizations_url":"https://api.github.com/users/jpvanhal/orgs","repos_url":"https://api.github.com/users/jpvanhal/repos","events_url":"https://api.github.com/users/jpvanhal/events{/privacy}","received_events_url":"https://api.github.com/users/jpvanhal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-10T08:05:10Z","updated_at":"2016-10-10T08:05:10Z","closed_at":null,"body":"We're using ptpython with Flask-Konch and noticed that the autocompletion crashes whenever ptpython tries to autocomplete Flask-SQLAlchemy queries. \r\n\r\nBelow is the minimal code to reproduce the issue in ptpython shell:\r\n\r\n```python\r\n>>> from flask import Flask\r\n>>> from flask_sqlalchemy import SQLAlchemy\r\n>>>\r\n>>> app = Flask(__name__)\r\n>>> db = SQLAlchemy()\r\n>>> db.init_app(app)\r\n>>>\r\n>>> class User(db.Model):\r\n...     __tablename__ = 'users'\r\n...      id = db.Column(db.Integer, primary_key=True)\r\n...      email = db.Column(db.Text)\r\n\r\n>>> User.query.filter_by(eException in thread Thread-168:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py\", line 801, in __bootstrap_inner\r\n    self.run()\r\n  File \"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py\", line 754, in run\r\n    self.__target(*self.__args, **self.__kwargs)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/prompt_toolkit/interface.py\", line 836, in run [F2] Menu - CPython 2.7.12\r\n    completions = list(buffer.completer.get_completions(document, complete_event))\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/ptpython/completer.py\", line 127, in get_completions\r\n    completions = script.completions()\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/api/__init__.py\", line 192, in completions\r\n    for call_sig in self.call_signatures():\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/api/__init__.py\", line 521, in call_signatures\r\n    self.source, self._pos)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/cache.py\", line 93, in wrapper\r\n    value = next(generator)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/cache.py\", line 115, in cache_call_signatures\r\n    yield evaluator.eval_element(call)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/cache.py\", line 41, in wrapper\r\n    rv = function(obj, *args, **kwargs)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/__init__.py\", line 187, in eval_element\r\n    types = self.eval_trailer(types, trailer)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/__init__.py\", line 257, in eval_trailer\r\n    new_types += self.find_types(typ, node)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/__init__.py\", line 120, in find_types\r\n    return f.find(scopes, search_global)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/debug.py\", line 52, in wrapper\r\n    result = func(*args, **kwargs)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/finder.py\", line 86, in find\r\n    names = self.filter_name(scopes)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/finder.py\", line 177, in filter_name\r\n    names = self.names_dict_lookup(names_dict, position)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/finder.py\", line 119, in names_dict_lookup\r\n    names = names_dict[search_str]\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/cache.py\", line 160, in wrapper\r\n    result = method(self, *args, **kwargs)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/jedi/evaluate/compiled/__init__.py\", line 263, in __getitem__\r\n    getattr(self._compiled_obj.obj, name)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py\", line 500, in __get__\r\n    return type.query_class(mapper, session=self.sa.session())\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py\", line 78, in __call__\r\n    return self.registry()\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/sqlalchemy/util/_collections.py\", line 990, in __call__\r\n    return self.registry.setdefault(key, self.createfunc())\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py\", line 771, in create_session\r\n    return SignallingSession(self, **options)\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py\", line 153, in __init__\r\n    self.app = app = db.get_app()\r\n  File \"/Users/janne/.virtualenvs/python-prompt-toolkit/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py\", line 922, in get_app\r\n    raise RuntimeError('application not registered on db '\r\nRuntimeError: application not registered on db instance and no application bound to current context\r\n```\r\n\r\nIs this a something that Jedi should be handling?\r\n"}}
{"actor":{"display_login":"jpvanhal"}}