Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 82 in superset/extensions/metastore_cache.py

View check run for this annotation

Codecov / codecov/patch

superset/extensions/metastore_cache.py#L82

Added line #L82 was not covered by tests

KeyValueDAO.upsert_entry(
resource=RESOURCE,
key=self.get_key(key),
Expand All @@ -90,6 +92,9 @@
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

Check warning on line 96 in superset/extensions/metastore_cache.py

View check run for this annotation

Codecov / codecov/patch

superset/extensions/metastore_cache.py#L96

Added line #L96 was not covered by tests

try:
KeyValueDAO.delete_expired_entries(RESOURCE)
KeyValueDAO.create_entry(
Expand All @@ -106,6 +111,9 @@
return False

def get(self, key: str) -> Any:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO

Check warning on line 115 in superset/extensions/metastore_cache.py

View check run for this annotation

Codecov / codecov/patch

superset/extensions/metastore_cache.py#L115

Added line #L115 was not covered by tests

return KeyValueDAO.get_value(RESOURCE, self.get_key(key), self.codec)

def has(self, key: str) -> bool:
Expand All @@ -116,4 +124,7 @@

@transaction()
def delete(self, key: str) -> Any:
# pylint: disable=import-outside-toplevel
from superset.daos.key_value import KeyValueDAO

Check warning on line 128 in superset/extensions/metastore_cache.py

View check run for this annotation

Codecov / codecov/patch

superset/extensions/metastore_cache.py#L128

Added line #L128 was not covered by tests

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
Loading