yousoph opened a new pull request, #41078:
URL: https://github.com/apache/superset/pull/41078

   ### Summary
   
   The Database field in the CSV/Excel/Columnar upload modal displayed a red 
validation warning even after a database had been successfully selected.
   
   **Root cause:** `validateDatabase` read `currentDatabaseId` from a stale 
closure. Ant Design fires the Ant Design Form validator synchronously on 
`onChange` — before React processes the `setCurrentDatabaseId` state update — 
so the validator always saw the previous value (`0`) and rejected.
   
   **Fix:** Use the `value` parameter that Ant Design passes directly to the 
validator (the current form field value) instead of the stale state variable.
   
   ```diff
   -const validateDatabase = (_: any, value: string) => {
   -  if (!currentDatabaseId) {
   +const validateDatabase = (
   +  _: any,
   +  value: { value: number; label: string } | null | undefined,
   +) => {
   +  if (!value?.value) {
        return Promise.reject(t('Selecting a database is required'));
      }
   ```
   
   ### Testing
   
   - Added a test in `UploadDataModal.test.tsx` that triggers validation errors 
via the Upload button, selects a database, and asserts the error message 
disappears.
   - Applies to CSV, Excel, and Columnar upload modals (all use the same 
`UploadDataModal` component).
   
   ### Checklist
   
   - [x] Bug fix (non-breaking change that fixes an issue)
   - [x] Test added


-- 
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