sha174n commented on code in PR #39303:
URL: https://github.com/apache/superset/pull/39303#discussion_r3297847040


##########
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:
   Skipping: `except (ValueError, Exception)` is semantically identical to 
`except Exception` (Exception is a superclass of ValueError), and the 
broad-except + rollback idiom matches the existing pattern in the sibling 
`post` and `delete` methods on this view (with the same intentional `# pylint: 
disable=broad-except`).



-- 
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]

Reply via email to