betodealmeida commented on a change in pull request #17536:
URL: https://github.com/apache/superset/pull/17536#discussion_r758551402
##########
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
+FILTER_STATE_CACHE_CONFIG: CacheConfig = {"CACHE_TYPE": "null"}
Review comment:
Question about this variable's name:
When we start using the KV store for other use cases in the future is the
idea that each one will have it's own cache configuration? Or would we have a
single cache configuration for all the endpoints implementing a KV store?
If the latter we should rename this config to something more generic, like
`KEY_VALUE_STORE_CONFIG`.
##########
File path: superset/key_value/commands/create.py
##########
@@ -0,0 +1,57 @@
+# 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 ABC, abstractmethod
+from secrets import token_urlsafe
+from typing import Any, Dict, Optional
+
+from flask_appbuilder.models.sqla import Model
+from flask_appbuilder.security.sqla.models import User
+from sqlalchemy.exc import SQLAlchemyError
+
+from superset.commands.base import BaseCommand
+from superset.key_value.commands.exceptions import KeyValueCreateFailedError
+
+logger = logging.getLogger(__name__)
+
+
+class CreateKeyValueCommand(BaseCommand, ABC):
+ def __init__(
+ self, user: User, resource_id: int, data: Dict[str, Any],
+ ):
+ self._actor = user
+ self._resource_id = resource_id
+ self._properties = data.copy()
+
+ def run(self) -> Model:
+ try:
+ key = token_urlsafe(48)
+ value = self._properties.get("value")
+ if value:
+ self.create(self._resource_id, key, value)
+ return key
+ except SQLAlchemyError as ex:
+ logger.exception(ex.exception)
Review comment:
`logger.exception` already logs the whole exception stack trace, it
might be more useful to add a message here:
```suggestion
logger.exception("Error running create command")
```
Though I'm not sure if `logger.exception` will show all the relevant
information from `ex.exception`, so it would be good to test my proposed
solution before accepting it. :)
(Same for the other commands.)
##########
File path: superset/dashboards/filter_state/api.py
##########
@@ -0,0 +1,246 @@
+# 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 typing import Type
+
+from flask import Response
+from flask_appbuilder.api import expose, protect, safe
+
+from superset.dashboards.filter_state.commands.create import
CreateFilterStateCommand
+from superset.dashboards.filter_state.commands.delete import
DeleteFilterStateCommand
+from superset.dashboards.filter_state.commands.get import GetFilterStateCommand
+from superset.dashboards.filter_state.commands.update import
UpdateFilterStateCommand
+from superset.extensions import event_logger
+from superset.key_value.api import KeyValueRestApi
+from superset.views.base_api import statsd_metrics
+
+logger = logging.getLogger(__name__)
+
+
+class DashboardFilterStateRestApi(KeyValueRestApi):
+ class_permission_name = "FilterStateRestApi"
+ resource_name = "dashboard"
+ openapi_spec_tag = "Filter State"
+
+ def get_create_command(self) -> Type[CreateFilterStateCommand]:
+ return CreateFilterStateCommand
+
+ def get_update_command(self) -> Type[UpdateFilterStateCommand]:
+ return UpdateFilterStateCommand
+
+ def get_get_command(self) -> Type[GetFilterStateCommand]:
+ return GetFilterStateCommand
+
+ def get_delete_command(self) -> Type[DeleteFilterStateCommand]:
+ return DeleteFilterStateCommand
Review comment:
Do you foresee any reasons why these should be methods, and not just
class attributes? Eg:
```python
create_command = CreateFilterStateCommand
```
--
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]