mistercrunch commented on a change in pull request #10645:
URL:
https://github.com/apache/incubator-superset/pull/10645#discussion_r474809234
##########
File path: superset/connectors/sqla/models.py
##########
@@ -629,12 +637,48 @@ def sql_url(self) -> str:
return self.database.sql_url + "?table_name=" + str(self.table_name)
def external_metadata(self) -> List[Dict[str, str]]:
- cols = self.database.get_columns(self.table_name, schema=self.schema)
- for col in cols:
- try:
- col["type"] = str(col["type"])
- except CompileError:
- col["type"] = "UNKNOWN"
+ db_engine_spec = self.database.db_engine_spec
+ if self.sql:
+ engine = self.database.get_sqla_engine()
+ parsed_query = ParsedQuery(self.sql)
+ if not parsed_query.is_readonly():
+ raise SupersetSecurityException(
+ SupersetError(
+
error_type=SupersetErrorType.DATASOURCE_SECURITY_ACCESS_ERROR,
+ message=_("Only `SELECT` statements are allowed"),
+ level=ErrorLevel.ERROR,
+ )
+ )
+ statements = parsed_query.get_statements()
+ if len(statements) > 1:
+ raise SupersetSecurityException(
+ SupersetError(
+
error_type=SupersetErrorType.DATASOURCE_SECURITY_ACCESS_ERROR,
+ message=_("Only single queries supported"),
+ level=ErrorLevel.ERROR,
+ )
+ )
+ with closing(engine.raw_connection()) as conn:
+ with closing(conn.cursor()) as cursor:
Review comment:
I'd like to have a single code path that does this. Is there a way we
can refactor/share code with the sqllab modules here?
https://github.com/apache/incubator-superset/blob/master/superset/sql_lab.py#L337
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]