chore(key-value): convert command to dao (#29344)

This commit is contained in:
Ville Brofeldt
2024-07-01 20:22:11 +03:00
committed by GitHub
parent 0cf676b574
commit 7d6e933348
36 changed files with 867 additions and 1162 deletions

View File

@@ -20,8 +20,9 @@ from typing import Any, Optional
from sqlalchemy.exc import SQLAlchemyError
from superset import db
from superset.commands.explore.permalink.base import BaseExplorePermalinkCommand
from superset.commands.key_value.create import CreateKeyValueCommand
from superset.daos.key_value import KeyValueDAO
from superset.explore.permalink.exceptions import ExplorePermalinkCreateFailedError
from superset.explore.utils import check_access as check_chart_access
from superset.key_value.exceptions import (
@@ -65,15 +66,12 @@ class CreateExplorePermalinkCommand(BaseExplorePermalinkCommand):
"datasource": self.datasource,
"state": self.state,
}
command = CreateKeyValueCommand(
resource=self.resource,
value=value,
codec=self.codec,
)
key = command.run()
if key.id is None:
entry = KeyValueDAO.create_entry(self.resource, value, self.codec)
db.session.flush()
key = entry.id
if key is None:
raise ExplorePermalinkCreateFailedError("Unexpected missing key id")
return encode_permalink_key(key=key.id, salt=self.salt)
return encode_permalink_key(key=key, salt=self.salt)
def validate(self) -> None:
pass