You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/01/24 22:04:49 UTC

[GitHub] [superset] ktmud commented on a change in pull request #18151: refactor: Moves the Explore form_data endpoint

ktmud commented on a change in pull request #18151:
URL: https://github.com/apache/superset/pull/18151#discussion_r791185706



##########
File path: superset/explore/form_data/commands/entry.py
##########
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing_extensions import TypedDict
+
+
+class Entry(TypedDict):

Review comment:
       Can we rename this to something like `TemporaryExploreState` to be more specific?

##########
File path: superset/explore/form_data/api.py
##########
@@ -96,41 +98,53 @@ def post(self, pk: int) -> Response:
             500:
               $ref: '#/components/responses/500'
         """
-        return super().post(pk)
+        if not request.is_json:
+            raise InvalidPayloadFormatError("Request is not JSON")
+        try:
+            item = self.add_model_schema.load(request.json)
+            args = CommandParameters(
+                actor=g.user,
+                dataset_id=item["dataset_id"],
+                chart_id=item.get("chart_id"),
+                value=item["value"],
+            )
+            key = CreateFormDataCommand(args).run()
+            return self.response(201, key=key)
+        except ValidationError as ex:
+            return self.response(400, message=ex.messages)
+        except (
+            ChartAccessDeniedError,
+            DatasetAccessDeniedError,
+            KeyValueAccessDeniedError,
+        ) as ex:
+            return self.response(403, message=str(ex))
+        except (ChartNotFoundError, DatasetNotFoundError) as ex:
+            return self.response(404, message=str(ex))

Review comment:
       We should have a general decorator to handle common 403 and 404 error if not already.
   
   Maybe in `superset.commands.exceptions` add a:
   
   ```python
   def handle_command_exceptions():
      ...
   ```

##########
File path: superset/explore/form_data/commands/entry.py
##########
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing_extensions import TypedDict
+
+
+class Entry(TypedDict):
+    owner: int
+    dataset_id: int
+    chart_id: int

Review comment:
       Shouldn't `dataset_id` and `chart_id` be `Optional[int]`?

##########
File path: superset/explore/form_data/commands/entry.py
##########
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing_extensions import TypedDict
+
+
+class Entry(TypedDict):
+    owner: int
+    dataset_id: int
+    chart_id: int
+    value: str

Review comment:
       Since this is already a typed dict and does not need to be generic, I'd recommend renaming `value` to `form_data`.

##########
File path: superset/explore/form_data/api.py
##########
@@ -96,41 +98,53 @@ def post(self, pk: int) -> Response:
             500:
               $ref: '#/components/responses/500'
         """
-        return super().post(pk)
+        if not request.is_json:
+            raise InvalidPayloadFormatError("Request is not JSON")

Review comment:
       Do we have a decorator for this? Might want to add one if not yet.




-- 
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: notifications-unsubscribe@superset.apache.org

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