chore(key-value): use json serialization for main resources (#23888)

This commit is contained in:
Ville Brofeldt
2023-05-04 08:04:05 +03:00
committed by GitHub
parent 10d640e940
commit f1fa1a733d
23 changed files with 293 additions and 70 deletions

View File

@@ -24,6 +24,7 @@ from flask import request, Response
from marshmallow import ValidationError
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.key_value.types import JsonKeyValueCodec
from superset.temporary_cache.commands.exceptions import (
TemporaryCacheAccessDeniedError,
TemporaryCacheResourceNotFoundError,
@@ -37,6 +38,8 @@ from superset.views.base_api import BaseSupersetApi, requires_json
logger = logging.getLogger(__name__)
CODEC = JsonKeyValueCodec()
class TemporaryCacheRestApi(BaseSupersetApi, ABC):
add_model_schema = TemporaryCachePostSchema()
@@ -69,7 +72,12 @@ class TemporaryCacheRestApi(BaseSupersetApi, ABC):
try:
item = self.add_model_schema.load(request.json)
tab_id = request.args.get("tab_id")
args = CommandParameters(resource_id=pk, value=item["value"], tab_id=tab_id)
args = CommandParameters(
resource_id=pk,
value=item["value"],
tab_id=tab_id,
codec=CODEC,
)
key = self.get_create_command()(args).run()
return self.response(201, key=key)
except ValidationError as ex:
@@ -89,6 +97,7 @@ class TemporaryCacheRestApi(BaseSupersetApi, ABC):
key=key,
value=item["value"],
tab_id=tab_id,
codec=CODEC,
)
key = self.get_update_command()(args).run()
return self.response(200, key=key)
@@ -101,7 +110,7 @@ class TemporaryCacheRestApi(BaseSupersetApi, ABC):
def get(self, pk: int, key: str) -> Response:
try:
args = CommandParameters(resource_id=pk, key=key)
args = CommandParameters(resource_id=pk, key=key, codec=CODEC)
value = self.get_get_command()(args).run()
if not value:
return self.response_404()