codeant-ai-for-open-source[bot] commented on code in PR #39171: URL: https://github.com/apache/superset/pull/39171#discussion_r3622833625
########## 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()) + data = ctx.storage.ephemeral.get("cachedData") Review Comment: **Suggestion:** The usage examples call ephemeral `set` without required options, which contradicts the implemented Tier 2 API and will cause runtime `TypeError` when copied by users. Update the examples to pass `EphemeralSetOptions(ttl=...)` so documentation matches executable behavior. [docstring mismatch] <details> <summary><b>Severity Level:</b> Minor ๐งน</summary> ```mdx - โ ๏ธ Docstring example matches visible Python protocol signature. - โ ๏ธ No concrete ephemeral storage implementation in this PR. - โ ๏ธ Example not runnable; get_context raises immediately. - โ ๏ธ Suggestion targets mismatch with unseen external API. ``` </details> <details> <summary><b>Steps of Reproduction โ </b></summary> ```mdx 1. Inspect the module docstring example in `superset-core/src/superset_core/extensions/context.py:31-40`; it shows `ctx.storage.ephemeral.set("lastRun", time.time())`. 2. Compare this example with the `StorageAccessor.set` protocol at lines 57-59, which accepts `(key: str, value: Any, ttl: int = 3600)` and makes the `ttl` argument optional via a default. 3. Inspect `get_context()` at lines 104-133; it raises `NotImplementedError`, so the example is not executable against any real storage implementation within this module. 4. No Python definition of `EphemeralSetOptions` or a different ephemeral `set` signature exists in the provided code, so the example call shape matches the visible protocol; the claimed runtime `TypeError` cannot be reproduced from actual code paths here. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a84006645daa47758cb9d4c21a506e98&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a84006645daa47758cb9d4c21a506e98&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-core/src/superset_core/extensions/context.py **Line:** 37:39 **Comment:** *Docstring Mismatch: The usage examples call ephemeral `set` without required options, which contradicts the implemented Tier 2 API and will cause runtime `TypeError` when copied by users. Update the examples to pass `EphemeralSetOptions(ttl=...)` so documentation matches executable behavior. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=7b3785e7103641df87aba1976b05318c63e2bc8121d22d6b518de6967410eca0&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=7b3785e7103641df87aba1976b05318c63e2bc8121d22d6b518de6967410eca0&reaction=dislike'>๐</a> -- 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]
