Skip to content

Commit

Permalink
fix(metastore-cache): import dao in methods (#29451)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jul 2, 2024
1 parent 7bb7fc0 commit 7f3c8ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 12 additions & 1 deletion superset/extensions/metastore_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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,
Expand Down Expand Up @@ -79,6 +78,9 @@ def _get_expiry(self, timeout: Optional[int]) -> Optional[datetime]:
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),
Expand All @@ -90,6 +92,9 @@ def set(self, key: str, value: Any, timeout: Optional[int] = None) -> bool:
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(
Expand All @@ -106,6 +111,9 @@ def add(self, key: str, value: Any, timeout: Optional[int] = None) -> bool:
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:
Expand All @@ -116,4 +124,7 @@ def has(self, key: str) -> bool:

@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))
8 changes: 2 additions & 6 deletions tests/integration_tests/extensions/metastore_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@

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,
KeyValueCodec,
PickleKeyValueCodec,
)

if TYPE_CHECKING:
from superset.extensions.metastore_cache import SupersetMetastoreCache

NAMESPACE = UUID("ee173d1b-ccf3-40aa-941c-985c15224496")

FIRST_KEY = "foo"
Expand All @@ -47,8 +45,6 @@

@pytest.fixture
def cache() -> SupersetMetastoreCache:
from superset.extensions.metastore_cache import SupersetMetastoreCache

return SupersetMetastoreCache(
namespace=NAMESPACE,
default_timeout=600,
Expand Down

0 comments on commit 7f3c8ef

Please sign in to comment.