michael-s-molina commented on code in PR #39171:
URL: https://github.com/apache/superset/pull/39171#discussion_r3624398861


##########
superset-core/src/superset_core/extensions/context.py:
##########
@@ -0,0 +1,136 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extension Context API for superset-core extensions.
+
+Provides access to the current extension's context, including metadata
+and scoped resources like storage. Extensions call `get_context()` to
+access their context during execution.
+
+The context is set by the host (Superset) during extension loading and
+is only available within extension code.
+
+Usage:
+    from superset_core.extensions.context import get_context
+
+    def setup():
+        ctx = get_context()
+
+        # Access extension metadata
+        print(f"Running {ctx.extension.displayName} v{ctx.extension.version}")
+
+        # Access extension-scoped storage
+        ctx.storage.ephemeral.set("lastRun", time.time(), 
EphemeralSetOptions(ttl=3600))
+        data = ctx.storage.ephemeral.get("cachedData")
+"""
+
+from __future__ import annotations
+
+from typing import Any, Protocol, TYPE_CHECKING
+
+if TYPE_CHECKING:
+    from superset_core.extensions.types import BaseExtension
+
+
+class StorageAccessor(Protocol):
+    """Protocol for storage access with user-scoped and shared modes."""
+
+    def get(self, key: str) -> Any:
+        """Get a value from storage."""
+        ...
+
+    def set(self, key: str, value: Any, ttl: int = 3600) -> None:
+        """Set a value in storage with optional TTL."""
+        ...

Review Comment:
   Fixed — removed the stale duplicate `StorageAccessor` protocol and pointed 
`ExtensionStorage.ephemeral`/`.persistent` at the real 
`EphemeralStateAccessor`/`PersistentStateAccessor` protocols, which already 
have the correct `options`-based `set()` signatures.



##########
superset/extensions/storage/persistent.py:
##########
@@ -0,0 +1,244 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Host implementation for Persistent State (Tier 3 Storage).
+
+Provides the concrete database-backed implementation that is injected into
+superset_core.extensions.storage.persistent at startup.
+"""
+
+from __future__ import annotations
+
+from typing import Any, ClassVar
+
+from superset_core.extensions.storage.persistent import (
+    PersistentListEntry,
+    PersistentListOptions,
+    PersistentListResult,
+    PersistentSetOptions,
+    PersistentState as CorePersistentState,
+)
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec
+from superset.extensions.storage.persistent_dao import ExtensionStorageDAO
+from superset.extensions.storage.utils import (
+    get_current_extension_id,
+    get_current_user_id,
+)
+from superset.utils.decorators import transaction
+
+
+def _get_extension_id() -> str:
+    """Get the current extension ID from context."""
+    return get_current_extension_id("persistent_state")
+
+
+def _list(
+    extension_id: str,
+    user_fk: int | None,
+    options: PersistentListOptions,
+) -> PersistentListResult:
+    """Shared `list` implementation for both scopes.
+
+    Unlike the REST API, ambient backend code has no SAFE_CODECS
+    restriction — every entry's value is decoded unconditionally, same as
+    `get_decoded_value()`.
+    """
+    entries, count = ExtensionStorageDAO.list_entries(
+        extension_id,
+        user_fk=user_fk,
+        resource_type=options.resource_type,
+        resource_uuid=options.resource_uuid,
+        page=options.page,
+        page_size=options.page_size,
+    )
+    return PersistentListResult(
+        entries=[
+            PersistentListEntry(
+                key=entry.key,
+                value=(
+                    get_codec(entry.codec).decode(entry.value)
+                    if entry.value is not None
+                    else None
+                ),

Review Comment:
   Not a bug — `ExtensionStorageDAO.list_entries` already decrypts each row via 
`_decrypt_if_needed` (persistent_dao.py) before returning it, so `entry.value` 
here is already plaintext bytes by the time `_list` decodes it with the codec. 
No change needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to