codeant-ai-for-open-source[bot] commented on code in PR #43633:
URL: https://github.com/apache/superset/pull/43633#discussion_r3877715709
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx:
##########
@@ -1631,6 +1635,49 @@ function DatasourceEditor({
onDatasourceChange,
]);
+ const renderCertificationFieldset = useCallback(() => {
+ const certification = getDatasetCertification(datasource.extra);
+
+ return isSqla ? (
+ <Fieldset
+ title={t('Certification')}
+ item={certification}
+ onChange={updatedCertification => {
+ onDatasourceChange({
+ ...datasource,
+ extra: setDatasetCertification(
+ datasource.extra,
+ updatedCertification,
+ ),
+ });
Review Comment:
**Suggestion:** The certification fieldset callback closes over the
`datasource` snapshot from its render. If a debounced edit in the adjacent
Basic fieldset updates `extra` and this callback fires before the next render,
spreading this stale snapshot and rebuilding `extra` from `datasource.extra`
overwrites that newer edit. Update certification against the latest datasource
state or use a shared ref/functional state update so edits from both fieldsets
are merged. [stale reference]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Rapid Basic and Certification edits can lose Extra changes.
- ⚠️ Custom metadata or warning metadata may be reverted.
- ⚠️ Dataset editor saves an outdated combined datasource.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3f3f7ced49b743b281b754cf0a7d116a&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=3f3f7ced49b743b281b754cf0a7d116a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
**Line:** 1645:1652
**Comment:**
*Stale Reference: The certification fieldset callback closes over the
`datasource` snapshot from its render. If a debounced edit in the adjacent
Basic fieldset updates `extra` and this callback fires before the next render,
spreading this stale snapshot and rebuilding `extra` from `datasource.extra`
overwrites that newer edit. Update certification against the latest datasource
state or use a shared ref/functional state update so edits from both fieldsets
are merged.
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%2F43633&comment_hash=c22080982ba348df14878d65848e44c141a396cb94e46bd6ccdecc0b3f723431&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43633&comment_hash=c22080982ba348df14878d65848e44c141a396cb94e46bd6ccdecc0b3f723431&reaction=dislike'>👎</a>
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/datasetCertification.ts:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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.
+ */
+
+export type DatasetCertification = Record<string, unknown> & {
+ certified_by?: string;
+ certification_details?: string;
+};
+
+type JsonObject = Record<string, unknown>;
+
+const isJsonObject = (value: unknown): value is JsonObject =>
+ typeof value === 'object' && value !== null && !Array.isArray(value);
+
+const parseExtra = (extra?: string): JsonObject | undefined => {
+ if (!extra?.trim()) {
+ return {};
+ }
+
+ try {
+ const parsed: unknown = JSON.parse(extra);
+ return isJsonObject(parsed) ? parsed : undefined;
+ } catch {
+ return undefined;
+ }
+};
+
+export const getDatasetCertification = (
+ extra?: string,
+): DatasetCertification => {
+ const certification = parseExtra(extra)?.certification;
+ if (!isJsonObject(certification)) {
+ return {};
+ }
+
+ return {
+ certified_by:
+ typeof certification.certified_by === 'string'
+ ? certification.certified_by
+ : undefined,
+ certification_details:
+ typeof certification.details === 'string'
+ ? certification.details
+ : undefined,
+ };
+};
+
+export const setDatasetCertification = (
+ extra: string | undefined,
+ { certified_by, certification_details }: DatasetCertification,
+): string => {
+ const parsedExtra = parseExtra(extra);
+
+ // Do not replace malformed raw metadata while the user is correcting it in
+ // the adjacent Extra editor.
+ if (!parsedExtra) {
+ return extra ?? '';
+ }
Review Comment:
**Suggestion:** When `extra` is malformed, the certification controls render
as editable because `getDatasetCertification` returns an empty object, but this
branch silently returns the original malformed string and discards any
certification values the user enters. The UI provides no indication that saving
those fields is ineffective; either surface the malformed-JSON validation state
and disable these controls or preserve the pending certification edit after the
Extra JSON is corrected. [incomplete implementation]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Dataset certification cannot be saved with malformed Extra.
- ⚠️ Certification inputs appear editable but reset.
- ⚠️ Users receive no malformed-metadata warning here.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=403d5a66d9d44e878b49cacc0048c7ce&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=403d5a66d9d44e878b49cacc0048c7ce&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/components/Datasource/components/DatasourceEditor/datasetCertification.ts
**Line:** 71:73
**Comment:**
*Incomplete Implementation: When `extra` is malformed, the
certification controls render as editable because `getDatasetCertification`
returns an empty object, but this branch silently returns the original
malformed string and discards any certification values the user enters. The UI
provides no indication that saving those fields is ineffective; either surface
the malformed-JSON validation state and disable these controls or preserve the
pending certification edit after the Extra JSON is corrected.
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%2F43633&comment_hash=cb4a578ffcfbafba9563943cb401cc54913183014f88c38df72b9d3c88e41522&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43633&comment_hash=cb4a578ffcfbafba9563943cb401cc54913183014f88c38df72b9d3c88e41522&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]