Skip to content
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

Fix raise error when query datasource #3298

Merged
merged 4 commits into from
Aug 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,12 +1039,8 @@ def explore(self, datasource_type, datasource_id):
slc = db.session.query(models.Slice).filter_by(id=slice_id).first()

error_redirect = '/slicemodelview/list/'
datasource = (
db.session.query(ConnectorRegistry.sources[datasource_type])
.filter_by(id=datasource_id)
.one()
)

datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session)
if not datasource:
flash(DATASOURCE_MISSING_ERR, "danger")
return redirect(error_redirect)
Expand Down Expand Up @@ -1119,13 +1115,8 @@ def filter(self, datasource_type, datasource_id, column):
:return:
"""
# TODO: Cache endpoint by user, datasource and column
datasource_class = ConnectorRegistry.sources[datasource_type]
datasource = (
db.session.query(datasource_class)
.filter_by(id=datasource_id)
.first()
)

datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session)
if not datasource:
return json_error_response(DATASOURCE_MISSING_ERR)
if not self.datasource_access(datasource):
Expand Down Expand Up @@ -2000,7 +1991,7 @@ def sql_json(self):
schema = request.form.get('schema') or None

session = db.session()
mydb = session.query(models.Database).filter_by(id=database_id).one()
mydb = session.query(models.Database).filter_by(id=database_id).first()

if not mydb:
json_error_response(
Expand Down Expand Up @@ -2138,13 +2129,8 @@ def csv(self, client_id):
def fetch_datasource_metadata(self):
datasource_id, datasource_type = (
request.args.get('datasourceKey').split('__'))
datasource_class = ConnectorRegistry.sources[datasource_type]
datasource = (
db.session.query(datasource_class)
.filter_by(id=int(datasource_id))
.first()
)

datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session)
# Check if datasource exists
if not datasource:
return json_error_response(DATASOURCE_MISSING_ERR)
Expand Down