codeant-ai-for-open-source[bot] commented on code in PR #37919:
URL: https://github.com/apache/superset/pull/37919#discussion_r3565186988
##########
superset-frontend/src/features/databases/DatabaseModal/DatabaseConnectionForm/EncryptedField.tsx:
##########
@@ -220,6 +252,7 @@ export const EncryptedField = ({
},
});
setFileList(info.fileList);
+ setPendingValidationValue(fileContent);
Review Comment:
**Suggestion:** The deferred upload-validation state is only cleared when
`paramValue` matches the uploaded content, but it is never reset when the
upload is removed/cancelled or replaced before that match happens. This leaves
stale pending state that can trigger a later validation on unrelated edits;
clear the pending value in remove/empty-file/error paths (and when switching
away from upload mode) so validation is tied only to the current upload action.
[stale reference]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
⚠️ DB credential validation may run from stale upload state.
⚠️ Stale pendingValidationValue can validate unrelated credential edits.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the database connection modal in the Superset UI; the dynamic form
uses
FORM_FIELD_MAP in
`superset-frontend/src/features/databases/DatabaseModal/DatabaseConnectionForm/constants.ts:3-26`,
where `credentials_info` and `service_account_info` are mapped to the
`EncryptedField`
component.
2. For a BigQuery or GSheets engine, the credential field is rendered via
`EncryptedField`
defined in `EncryptedField.tsx:53-63`, with `pendingValidationValue` state
declared at
`EncryptedField.tsx:75-77` and the deferred validation `useEffect` at
`EncryptedField.tsx:143-151`.
3. In create mode, leave the upload option selected (default) and upload a
JSON
credentials file; the upload handler at `EncryptedField.tsx:241-255` calls
`changeMethods.onParametersChange` with `target.value = fileContent` and then
`setPendingValidationValue(fileContent)` while the parent
`db.parameters[encryptedField]`
still contains the previous value.
4. Before the parent reducer has echoed the uploaded content back into
`db.parameters[encryptedField]`, click the upload remove control; the
`onRemove` handler
at `EncryptedField.tsx:231-239` clears `fileList` and writes an empty string
to the
parameter but never calls `setPendingValidationValue(null)`, so
`pendingValidationValue`
still holds the original `fileContent`.
5. Switch to the copy-paste mode using the credentials method select wired at
`EncryptedField.tsx:173-181`, then paste the same JSON content into the
textarea rendered
by `ValidatedInput` at `EncryptedField.tsx:198-218`; the parent once again
commits this
value into `db.parameters[encryptedField]`.
6. When the parent re-renders with `paramValue` equal to the newly committed
credentials,
the effect at `EncryptedField.tsx:143-151` observes that
`pendingValidationValue` is
non-null and equals `paramValue` and fires `getValidation()`, even though
the marker
originated from the earlier upload flow that was removed, demonstrating that
the deferred
validation state is stale and can trigger validation on a later, unrelated
edit.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dce96d8f44a1481cbcc7c6198227276c&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=dce96d8f44a1481cbcc7c6198227276c&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/features/databases/DatabaseModal/DatabaseConnectionForm/EncryptedField.tsx
**Line:** 75:255
**Comment:**
*Stale Reference: The deferred upload-validation state is only cleared
when `paramValue` matches the uploaded content, but it is never reset when the
upload is removed/cancelled or replaced before that match happens. This leaves
stale pending state that can trigger a later validation on unrelated edits;
clear the pending value in remove/empty-file/error paths (and when switching
away from upload mode) so validation is tied only to the current upload action.
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%2F37919&comment_hash=e69acdfcbc3a0db6a35098121c423ac3a9324be1674b0e2a079c480e15584c5d&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37919&comment_hash=e69acdfcbc3a0db6a35098121c423ac3a9324be1674b0e2a079c480e15584c5d&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]