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 2021/11/24 17:26:25 UTC

[GitHub] [superset] villebro commented on a change in pull request #17536: feat: Adds a key-value endpoint to store the state of dashboard filters

villebro commented on a change in pull request #17536:
URL: https://github.com/apache/superset/pull/17536#discussion_r756285068



##########
File path: superset/key_value/api.py
##########
@@ -0,0 +1,84 @@
+# 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.
+import logging
+from abc import abstractmethod
+from typing import Any
+
+from flask import g, request, Response
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+
+from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
+from superset.exceptions import InvalidPayloadFormatError
+from superset.key_value.commands.create import CreateKeyValueCommand
+from superset.key_value.commands.delete import DeleteKeyValueCommand
+from superset.key_value.commands.get import GetKeyValueCommand
+from superset.key_value.commands.update import UpdateKeyValueCommand
+from superset.key_value.schemas import KeyValuePostSchema, KeyValuePutSchema
+from superset.models.key_value import KeyValueEntry
+from superset.views.base_api import BaseSupersetModelRestApi
+
+logger = logging.getLogger(__name__)
+
+
+class KeyValueRestApi(BaseSupersetModelRestApi):

Review comment:
       I think you will need to extend `abc.ABC` here to ensure all `abstractmethod`s are implemented: 
   ```python
   from abc import ABC
   
   class KeyValueRestApi(BaseSupersetModelRestApi, ABC):
   ```

##########
File path: superset/key_value/utils.py
##########
@@ -0,0 +1,26 @@
+# 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 import Any
+
+
+def cache_key(*args: Any) -> str:
+    result = ""
+    separator = ""
+    for arg in args:
+        result += separator + str(arg)
+        separator = ";"
+    return result

Review comment:
       This could perhaps be slightly simplified, something like
   ```python
   SEPARATOR = ";"
   
   def cache_key(*args: Any) -> str:
       return SEPARATOR.join(args)
   ```

##########
File path: superset/config.py
##########
@@ -560,6 +560,9 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
 # Cache for datasource metadata and query results
 DATA_CACHE_CONFIG: CacheConfig = {"CACHE_TYPE": "null"}
 
+# Cache for filters state
+FILTERS_STATE_CACHE_CONFIG: CacheConfig = {"CACHE_TYPE": "null"}

Review comment:
       nit, but we've been renaming variables etc from `filtersState` to `filterState` in the frontend. so I'd personally prefer `filter_state` here.

##########
File path: superset/key_value/schemas.py
##########
@@ -0,0 +1,29 @@
+# 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 marshmallow import fields, Schema
+
+
+class KeyValuePostSchema(Schema):
+    value = fields.String(
+        required=True, allow_none=False, description="Any type of JSON supported value."
+    )

Review comment:
       Do we want to enforce some certain type here? I wonder if we should force this to be a `fields.Dict` to make sure all values are JSON objects. This would make sure the frontend never has to at least worry about receiving something that's unparseable.




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