WenQiangW commented on a change in pull request #10645:
URL: https://github.com/apache/incubator-superset/pull/10645#discussion_r489299571
##########
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:
+ query = statements[0]
Review comment:
` query = self.database.apply_limit_to_sql(query, limit)`
Respect
I think it’s better to add a restriction, because here only a few data needs to be queried.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
|