bito-code-review[bot] commented on code in PR #39303:
URL: https://github.com/apache/superset/pull/39303#discussion_r3297850162
##########
superset/views/sql_lab/views.py:
##########
@@ -268,11 +282,24 @@ def delete(self, table_schema_id: int) -> FlaskResponse:
@has_access_api
@expose("/<int:table_schema_id>/expanded", methods=("POST",))
def expanded(self, table_schema_id: int) -> FlaskResponse:
- payload = json.loads(request.form["expanded"])
- (
- db.session.query(TableSchema)
- .filter_by(id=table_schema_id)
- .update({"expanded": payload})
- )
- response = json.dumps({"id": table_schema_id, "expanded": payload})
- return json_success(response)
+ try:
+ tab_state_id = (
+ db.session.query(TableSchema.tab_state_id)
+ .filter_by(id=table_schema_id)
+ .scalar()
+ )
+ if tab_state_id is None:
+ return json_error_response(__("Not found"), status=404)
+ owner_id = _get_owner_id(tab_state_id)
+ if owner_id is None or owner_id != get_user_id():
+ return json_error_response(__("Forbidden"), status=403)
+ payload = json.loads(request.form["expanded"])
+ db.session.query(TableSchema).filter_by(id=table_schema_id).update(
+ {"expanded": payload}
+ )
+ db.session.commit()
+ response = json.dumps({"id": table_schema_id, "expanded": payload})
+ return json_success(response)
+ except Exception as ex: # pylint: disable=broad-except
Review Comment:
<!-- Bito Reply -->
The suggestion to catch specific exceptions like `SQLAlchemyError` instead
of a broad `Exception` is valid in general code quality practices. However, in
this case, the existing pattern of catching `ValueError` and `Exception` is
intentional for top-level request handlers. It ensures that unexpected errors
are converted into structured JSON responses rather than 500 errors. Since this
PR is focused on security and not on improving exception handling, narrowing
the catch is out of scope.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]