Skip to content

Commit

Permalink
Parse params with trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Kyryliuk committed Dec 15, 2016
1 parent a708a5e commit e174406
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion superset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def alter_params(self, **kwargs):
@property
def params_dict(self):
if self.params:
return json.loads(self.params)
params = re.sub(",[ \t\r\n]+}", "}", self.params)
params = re.sub(",[ \t\r\n]+\]", "]", params)
return json.loads(params)
else:
return {}

Expand Down
5 changes: 4 additions & 1 deletion superset/source_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def get_datasource_by_name(cls, session, datasource_type, datasource_name,
schema, database_name):
datasource_class = SourceRegistry.sources[datasource_type]
datasources = session.query(datasource_class).all()
db_ds = [d for d in datasources if d.database.name == database_name and

# Filter datasoures that don't have database.
db_ds = [d for d in datasources if d.database and
d.database.name == database_name and
d.name == datasource_name and schema == schema]
return db_ds[0]

Expand Down
5 changes: 5 additions & 0 deletions tests/import_export_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def create_slice(self, name, ds_id=None, id=None, db_name='main',
'datasource_name': table_name,
'database_name': db_name,
'schema': '',
# Test for trailing commas
"metrics": [
"sum__signup_attempt_email",
"sum__signup_attempt_facebook",
],
}

if table_name and not ds_id:
Expand Down

0 comments on commit e174406

Please sign in to comment.