You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by gi...@git.apache.org on 2017/09/18 13:58:24 UTC
[GitHub] RobinDavid opened a new issue #3483: ModelView flask-appbuilder "style" on a separate db (SQLALCHEMY_BINDS)
RobinDavid opened a new issue #3483: ModelView flask-appbuilder "style" on a separate db (SQLALCHEMY_BINDS)
URL: https://github.com/apache/incubator-superset/issues/3483
### Context
I am trying to use the flask-appbuilder `ModelView` in superset in order to be able to list, show and more especially editing entries which does not seems possible out of the box with superset. Importing the database in superset and ploting graph out of it works perfectly fine but I am willing to have more "flask-appbuilder style" access to the models to edit entries and adding custom views.
### Setup
I am adding in `config.py`:
```python
SQLALCHEMY_BINDS = {
'mybind': 'sqlite:///'+MY_DATABASE_FILE
}
```
Then create a model and attach it to the menu:
```python
class Band(Model):
__tablename__ = "Band"
__bind_key__ = "mybind"
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
name = Column(String, unique=True, nullable=False)
class BandView(ModelView):
datamodel = SQLAInterface(Band)
appbuilder.add_view(BandView, "Band", icon="", category="Custom Views")
```
When accessing `/bandview/list/ ` I have:
```
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Band [SQL: 'SELECT count(?) AS count_1 \nFROM "Band"'] [parameters: ('*',)]
```
### Glimpse of debug
The weird thing is that the database seems properly binded and is accessible from the debugging console:
```python
from superset import db
db.get_binds()
{Table('Band', MetaData(bind=None), [...]): Engine(sqlite:////PATH_TO_MY_DB),
[.... all the tables ]
}
```
and we can also make queries in command line:
```python
from superset.models.core import Band #I did put it in the core module for now
db.session.query(Band).all()
[all entries]
```
### Conclusion
* How does the superset database source lookup works ? Does it vary from flask-appbuilder
* Do I had badly register the Bluerpint ?
I was wondering, if superset provides a more idiomatic way to add custom functionalities like this ? Maybe there is a simpler way to do what I am willing to do.
> Note this works fine in a flask appbuilder app.
By the way thank you very much for superset that is a super awesome tool :wink:
### Superset version
0.19.1
Git: e22aecb0d1244bae49d3e5b36ef2f9ddc7517c1a
### Expected results
I am expecting the similar output than with flask-appbuilder, a listing of entries and the possibility to show entries and to edit them.
### Actual results
The table is not found with the following backtrace:
```
2017-09-18 15:28:32,610:INFO:werkzeug:127.0.0.1 - - [18/Sep/2017 15:28:32] "GET /bandview/list/ HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask_appbuilder/security/decorators.py", line 26, in wraps
return f(self, *args, **kwargs)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask_appbuilder/views.py", line 475, in list
widgets = self._list()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask_appbuilder/baseviews.py", line 877, in _list
page_size=page_size)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask_appbuilder/baseviews.py", line 791, in _get_list_widget
count, lst = self.datamodel.query(joined_filters, order_column, order_direction, page=page, page_size=page_size)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/flask_appbuilder/models/sqla/interface.py", line 111, in query
count = query_count.scalar()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2843, in scalar
ret = self.one()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2814, in one
ret = self.one_or_none()
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2784, in one_or_none
ret = list(self)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2855, in __iter__
return self._execute_and_instances(context)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2878, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 945, in execute
return meth(self, multiparams, params)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement
compiled_sql, distilled_params
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
context)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
exc_info
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
context)
File "/home/robin/.virtualenvs/superset/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Band [SQL: 'SELECT count(?) AS count_1 \nFROM "Band"'] [parameters: ('*',)]
```
**It does not looks to be entirely superset related error but I can't figure where does the issue come from.**
### Steps to reproduce
Creating a model as described hereabove.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services