upload file using model view failed
Make sure these boxes are checked before submitting your issue - thank you!
- [x] I have checked the superset logs for python stacktraces and included it here as text if there are any.
- [x] I have reproduced the issue with at least the latest released version of superset.
- [x] I have checked the issue tracker for the same issue and I haven't found one similar.
Superset version
master branch
Expected results
follow the sample from flask app builder example: https://github.com/dpgaspar/Flask-AppBuilder/tree/master/examples/quickfiles
I tried to use a F.A.B project, it worked fine, but in superset, it failed.
Actual results
when inserting database, it got null for file column, the errors like below:
2019-03-13 14:39:00,143:ERROR:flask_appbuilder.models.sqla.interface:Add record error: (MySQLdb._exceptions.OperationalError) (1048, "Column 'file' cannot be null") [SQL: 'INSERT INTO static_files (file, description) VALUES (%s, %s)'] [parameters: (None, 'test file upload')] (Background on this error at: http://sqlalche.me/e/e3q8) Traceback (most recent call last): File "/home/lyx/visualBI/venv/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/home/lyx/visualBI/venv/lib64/python3.6/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute cursor.execute(statement, parameters) File "/home/lyx/visualBI/venv/lib64/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query)
Steps to reproduce
(1) click add button to redirect to add page. (2) choose a file (3) input the description (4) click submit
Is there anybody can help? The code is simple.
(1) Add the following to core.py in the folder models:
from flask import Markup
from flask_appbuilder.models.mixins import FileColumn
from flask_appbuilder.filemanager import get_file_original_name
class StaticFile(Model):
__tablename__ = 'static_files'
id = Column(Integer, primary_key=True)
file_name = Column(String(250))
file = Column(FileColumn, nullable=False)
description = Column(String(150))
def download(self):
return Markup(
'<a href="' + url_for('StaticFileModelView.download', filename=str(self.file)) + '">Download</a>')
def file_name(self):
return get_file_original_name(str(self.file))`
(2) Add the following to core.py in the folder views:
`
from flask_appbuilder import ModelView
class StaticFileModelView(ModelView):
datamodel = SQLAInterface(models.StaticFile)
label_columns = {'file_name': 'File Name', 'download': 'Download'}
add_columns = ['file', 'description']
edit_columns = ['file', 'description']
list_columns = ['file_name', 'download']
show_columns = ['file_name', 'download']
appbuilder.add_view(
StaticFileModelView,
'Upload static File',
label=__('upload static File'),
icon='fa-file',
category='Manage')
This doesn't seem like a Superset issue really, this is just FAB, but if you take a moment to read the stack trace you'll see that file is None.
Idk though, but this is out of scope for this project, you're extending in unsupported ways, so I'd suggest to open a FAB issue.