This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f3c8efab0 fix(metastore-cache): import dao in methods (#29451)
7f3c8efab0 is described below

commit 7f3c8efab001a01e0a7c146f14f04be855bf82de
Author: Ville Brofeldt <[email protected]>
AuthorDate: Tue Jul 2 15:28:42 2024 +0300

    fix(metastore-cache): import dao in methods (#29451)
---
 superset/extensions/metastore_cache.py                     | 13 ++++++++++++-
 tests/integration_tests/extensions/metastore_cache_test.py |  8 ++------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/superset/extensions/metastore_cache.py 
b/superset/extensions/metastore_cache.py
index 1195bd8edf..197dac9386 100644
--- a/superset/extensions/metastore_cache.py
+++ b/superset/extensions/metastore_cache.py
@@ -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))
diff --git a/tests/integration_tests/extensions/metastore_cache_test.py 
b/tests/integration_tests/extensions/metastore_cache_test.py
index 238e8fd46a..401c2f988b 100644
--- a/tests/integration_tests/extensions/metastore_cache_test.py
+++ b/tests/integration_tests/extensions/metastore_cache_test.py
@@ -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,

Reply via email to