villebro commented on a change in pull request #10645:
URL:
https://github.com/apache/incubator-superset/pull/10645#discussion_r475116658
##########
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:
In this particular case the work is very much synchronous, but I agree
that the single code path is desirable (this solution was a compromise for
quick delivery as I feel `sql_lab.py` and `result_set.py` are in need of more
comprehensive refactoring outside the scope of this PR). I have a proposal in
mind that should be a small step in the right direction without having to
derail this PR too much. Will update this PR shortly.
----------------------------------------------------------------
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]