codeant-ai-for-open-source[bot] commented on code in PR #40444:
URL: https://github.com/apache/superset/pull/40444#discussion_r3304468668


##########
superset-frontend/src/core/dataset/index.ts:
##########
@@ -0,0 +1,62 @@
+/**
+ * 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-internal implementation of the `dataset` namespace.
+ *
+ * Dataset page components call `setCurrentDataset` to publish context as they
+ * load. Extensions consume the stable `DatasetContext` contract; they are

Review Comment:
   **Suggestion:** `onDidChangeDataset` passes the same mutable object 
reference stored in `currentDataset` directly to listeners, so any listener 
mutation can corrupt shared host state and affect later reads. Emit a cloned 
payload (and preferably store an immutable copy) before notifying subscribers. 
[stale reference]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ One extension can corrupt dataset context for all others.
   - ⚠️ getCurrentDataset returns mutated data, not original snapshot.
   - ⚠️ Subtle cross-extension bugs from hidden shared object mutation.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. The host dataset namespace keeps its current state in `currentDataset` 
and updates it
   via `setCurrentDataset` implemented in
   `superset-frontend/src/core/dataset/index.ts:21-24`, where `currentDataset = 
ctx` assigns
   the caller-provided `DatasetContext` object directly.
   
   2. After updating, `setCurrentDataset` notifies subscribers with 
`listeners.forEach(fn =>
   fn(ctx))` (`src/core/dataset/index.ts:22-24`), passing the same `ctx` 
reference that was
   just stored in `currentDataset`, without cloning or freezing it.
   
   3. Extensions are expected to subscribe using `dataset.onDidChangeDataset` 
as documented
   in `packages/superset-core/src/dataset/index.ts:62-70` (e.g., `const sub =
   dataset.onDidChangeDataset(ds => { ... });`); if any subscriber mutates 
fields on the
   received `ds` object (for example, normalizing strings or attaching metadata 
properties),
   it is mutating the same object instance saved in `currentDataset`.
   
   4. Subsequent calls to `dataset.getCurrentDataset()` in the host 
implementation
   (`superset-frontend/src/core/dataset/index.ts:28-29`) return `{ 
...currentDataset }`,
   which is a shallow copy of the already-mutated object; thus all future 
consumers,
   including other extensions, observe the corrupted values introduced by one 
subscriber,
   breaking isolation between internal host state and extension listeners and 
making bugs
   dependent on subscription order and mutation patterns.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=05e16aec88c7442db04d0edbf0b617f2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=05e16aec88c7442db04d0edbf0b617f2&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-frontend/src/core/dataset/index.ts
   **Line:** 22:24
   **Comment:**
        *Stale Reference: `onDidChangeDataset` passes the same mutable object 
reference stored in `currentDataset` directly to listeners, so any listener 
mutation can corrupt shared host state and affect later reads. Emit a cloned 
payload (and preferably store an immutable copy) before notifying subscribers.
   
   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%2F40444&comment_hash=d209731eb786a4aed5081db4d80bcac13c8080a20704a83435c8afd0c97e91b7&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40444&comment_hash=d209731eb786a4aed5081db4d80bcac13c8080a20704a83435c8afd0c97e91b7&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]

Reply via email to