fix(metastore-cache): import dao in methods (#29451)

This commit is contained in:
Ville Brofeldt
2024-07-02 15:28:42 +03:00
committed by GitHub
parent 7bb7fc0f49
commit 7f3c8efab0
2 changed files with 14 additions and 7 deletions

View File

@@ -24,7 +24,6 @@ from flask_caching import BaseCache
from sqlalchemy.exc import SQLAlchemyError
from superset import db
from superset.daos.key_value import KeyValueDAO
from superset.key_value.exceptions import KeyValueCreateFailedError
from superset.key_value.types import (
KeyValueCodec,
@@ -79,6 +78,9 @@ class SupersetMetastoreCache(BaseCache):
return None
def set(self, key: str, value: Any, timeout: Optional[int] = None) -> bool:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO
KeyValueDAO.upsert_entry(
resource=RESOURCE,
key=self.get_key(key),
@@ -90,6 +92,9 @@ class SupersetMetastoreCache(BaseCache):
return True
def add(self, key: str, value: Any, timeout: Optional[int] = None) -> bool:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO
try:
KeyValueDAO.delete_expired_entries(RESOURCE)
KeyValueDAO.create_entry(
@@ -106,6 +111,9 @@ class SupersetMetastoreCache(BaseCache):
return False
def get(self, key: str) -> Any:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO
return KeyValueDAO.get_value(RESOURCE, self.get_key(key), self.codec)
def has(self, key: str) -> bool:
@@ -116,4 +124,7 @@ class SupersetMetastoreCache(BaseCache):
@transaction()
def delete(self, key: str) -> Any:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO
return KeyValueDAO.delete_entry(RESOURCE, self.get_key(key))

View File

@@ -18,13 +18,14 @@ from __future__ import annotations
from contextlib import nullcontext
from datetime import datetime, timedelta
from typing import Any, TYPE_CHECKING
from typing import Any
from uuid import UUID
import pytest
from flask.ctx import AppContext
from freezegun import freeze_time
from superset.extensions.metastore_cache import SupersetMetastoreCache
from superset.key_value.exceptions import KeyValueCodecEncodeException
from superset.key_value.types import (
JsonKeyValueCodec,
@@ -32,9 +33,6 @@ from superset.key_value.types import (
PickleKeyValueCodec,
)
if TYPE_CHECKING:
from superset.extensions.metastore_cache import SupersetMetastoreCache
NAMESPACE = UUID("ee173d1b-ccf3-40aa-941c-985c15224496")
FIRST_KEY = "foo"
@@ -47,8 +45,6 @@ SECOND_VALUE = "qwerty"
@pytest.fixture
def cache() -> SupersetMetastoreCache:
from superset.extensions.metastore_cache import SupersetMetastoreCache
return SupersetMetastoreCache(
namespace=NAMESPACE,
default_timeout=600,