codeant-ai-for-open-source[bot] commented on code in PR #39918:
URL: https://github.com/apache/superset/pull/39918#discussion_r3198026298
##########
superset-frontend/src/components/Datasource/DatasourceModal/index.tsx:
##########
@@ -113,14 +113,14 @@ const DatasourceModal:
FunctionComponent<DatasourceModalProps> = ({
const buildPayload = (datasource: Record<string, any>) => {
const payload: Record<string, any> = {
table_name: datasource.table_name,
- database_id: datasource.database?.id,
+ database_id: datasource.database?.id ?? null,
Review Comment:
**🟠 Architect Review — HIGH**
The modal now always sends `database_id`, using `null` when no database is
selected, but the backend update contract does not accept `null` for this field
(`DatasetPutSchema.database_id` is non-nullable and `SqlaTable.database_id` is
a non-nullable column). When a user clears the database in the modal, the PUT
`/api/v1/dataset/<id>` request will fail validation instead of clearing or
leaving the database unchanged.
**Suggestion:** Align the frontend with the backend by either keeping
database required in the UI and omitting `database_id` when "cleared", or
extending the backend (schema, model, and update command) to explicitly support
nullable database references before sending `null` from the modal.
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20an%20%2A%2AArchitect%20%2F%20Logical%20Review%2A%2A%20comment%20left%20during%20a%20code%20review.%20These%20reviews%20are%20first-class%2C%20important%20findings%20%E2%80%94%20not%20optional%20suggestions.%20Do%20NOT%20dismiss%20this%20as%20a%20%27big%20architectural%20change%27%20just%20because%20the%20title%20says%20architect%20review%3B%20most%20of%20these%20can%20be%20resolved%20with%20a%20small%2C%20localized%20fix%20once%20the%20intent%20is%20understood.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fcomponents%2FDatasource%2FDatasourceModal%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20116%3A116%0A%2A%2AComment%3A%2A%2A%0A%09%2AHIGH%3A%20The%20modal%20now%20always%20sends%20%60database_id%60%2C%20using%20%60null%60%20when%20no%20database%20is%20selected%2C%20but%20the%20backend%20update%20contract%20does%20not%20accept%20%60null%60%20for%20this%20field%20%28%60DatasetPutSchema.database_id%60%20is%
20non-nullable%20and%20%60SqlaTable.database_id%60%20is%20a%20non-nullable%20column%29.%20When%20a%20user%20clears%20the%20database%20in%20the%20modal%2C%20the%20PUT%20%60%2Fapi%2Fv1%2Fdataset%2F%3Cid%3E%60%20request%20will%20fail%20validation%20instead%20of%20clearing%20or%20leaving%20the%20database%20unchanged.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AIf%20a%20suggested%20approach%20is%20provided%20above%2C%20use%20it%20as%20the%20authoritative%20instruction.%20If%20no%20explicit%20code%20suggestion%20is%20given%2C%20you%20MUST%20still%20draft%20and%20apply%20your%20own%20minimal%2C%20localized%20fix%20%E2%80%94%20do%20not%20punt%20back%20with%20%27no%20suggestion%20provided%2C%20review%20manually%27.%20Keep%20the%20change%20as%20small%20as%20possible%3A%20add%20a%20guard%20clause%2C%20gate%20on%20a%20loading%20stat
e%2C%20reorder%20an%20await%2C%20wrap%20in%20a%20conditional%2C%20etc.%20Do%20not%20refactor%20surrounding%20code%20or%20expand%20scope%20beyond%20the%20finding.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20an%20%2A%2AArchitect%20%2F%20Logical%20Review%2A%2A%20comment%20left%20during%20a%20code%20review.%20These%20reviews%20are%20first-class%2C%20important%20findings%20%E2%80%94%20not%20optional%20suggestions.%20Do%20NOT%20dismiss%20this%20as%20a%20%27big%20architectural%20change%27%20just%20because%20the%20title%20says%20architect%20review%3B%20most%20of%20these%20can%20be%20resolved%20with%20a%20small%2C%
20localized%20fix%20once%20the%20intent%20is%20understood.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fcomponents%2FDatasource%2FDatasourceModal%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20116%3A116%0A%2A%2AComment%3A%2A%2A%0A%09%2AHIGH%3A%20The%20modal%20now%20always%20sends%20%60database_id%60%2C%20using%20%60null%60%20when%20no%20database%20is%20selected%2C%20but%20the%20backend%20update%20contract%20does%20not%20accept%20%60null%60%20for%20this%20field%20%28%60DatasetPutSchema.database_id%60%20is%20non-nullable%20and%20%60SqlaTable.database_id%60%20is%20a%20non-nullable%20column%29.%20When%20a%20user%20clears%20the%20database%20in%20the%20modal%2C%20the%20PUT%20%60%2Fapi%2Fv1%2Fdataset%2F%3Cid%3E%60%20request%20will%20fail%20validation%20instead%20of%20clearing%20or%20leaving%20the%20database%20unchanged.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%
20please%20make%20it%20concise.%0AIf%20a%20suggested%20approach%20is%20provided%20above%2C%20use%20it%20as%20the%20authoritative%20instruction.%20If%20no%20explicit%20code%20suggestion%20is%20given%2C%20you%20MUST%20still%20draft%20and%20apply%20your%20own%20minimal%2C%20localized%20fix%20%E2%80%94%20do%20not%20punt%20back%20with%20%27no%20suggestion%20provided%2C%20review%20manually%27.%20Keep%20the%20change%20as%20small%20as%20possible%3A%20add%20a%20guard%20clause%2C%20gate%20on%20a%20loading%20state%2C%20reorder%20an%20await%2C%20wrap%20in%20a%20conditional%2C%20etc.%20Do%20not%20refactor%20surrounding%20code%20or%20expand%20scope%20beyond%20the%20finding.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0
A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is an **Architect / Logical Review** comment left during a code review.
These reviews are first-class, important findings — not optional suggestions.
Do NOT dismiss this as a 'big architectural change' just because the title says
architect review; most of these can be resolved with a small, localized fix
once the intent is understood.
**Path:**
superset-frontend/src/components/Datasource/DatasourceModal/index.tsx
**Line:** 116:116
**Comment:**
*HIGH: The modal now always sends `database_id`, using `null` when no
database is selected, but the backend update contract does not accept `null`
for this field (`DatasetPutSchema.database_id` is non-nullable and
`SqlaTable.database_id` is a non-nullable column). When a user clears the
database in the modal, the PUT `/api/v1/dataset/<id>` request will fail
validation instead of clearing or leaving the database unchanged.
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.
If a suggested approach is provided above, use it as the authoritative
instruction. If no explicit code suggestion is given, you MUST still draft and
apply your own minimal, localized fix — do not punt back with 'no suggestion
provided, review manually'. Keep the change as small as possible: add a guard
clause, gate on a loading state, reorder an await, wrap in a conditional, etc.
Do not refactor surrounding code or expand scope beyond the finding.
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>
##########
superset-frontend/src/components/Datasource/DatasourceModal/index.tsx:
##########
@@ -113,14 +113,14 @@ const DatasourceModal:
FunctionComponent<DatasourceModalProps> = ({
const buildPayload = (datasource: Record<string, any>) => {
const payload: Record<string, any> = {
table_name: datasource.table_name,
- database_id: datasource.database?.id,
+ database_id: datasource.database?.id ?? null,
Review Comment:
**Suggestion:** Setting `database_id` to `null` will break dataset saves
because the backend `DatasetPutSchema` defines `database_id` as an integer
without `allow_none=True`, so a cleared value triggers request validation
errors. Only send `database_id` when a valid numeric id exists (or align the
backend schema/command to explicitly accept and handle nulls). [integration bug]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Editing dataset and clearing database breaks save request.
- ⚠️ Dataset edit modal shows backend validation error instead.
- ⚠️ Prevents intended "clear database" workflow from functioning.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the dataset list page implemented in
`superset-frontend/src/pages/DatasetList/index.tsx` and click to edit any
dataset, which
sets `datasetCurrentlyEditing` and renders `<DatasourceModal>` at lines
26–32 and 26–32 &
26–32 & 26–32 and specifically 1430–1469 where `<DatasourceModal
datasource={datasetCurrentlyEditing} ... />` is instantiated.
2. In the resulting `DatasourceModal` component
(`superset-frontend/src/components/Datasource/DatasourceModal/index.tsx`),
clear the
database field so that the `datasource` object passed to `buildPayload`
(defined around
lines 113–191) has `datasource.database` unset/undefined.
3. Click "Save", which triggers `onConfirmSave` in `DatasourceModal`
(`index.tsx` lines
193–201); this calls `SupersetClient.put` to `PUT
/api/v1/dataset/{currentDatasource.id}`
with `jsonPayload: buildPayload(currentDatasource)`. With a cleared database,
`buildPayload` sets `database_id` to `datasource.database?.id ?? null` (line
116), so the
outbound JSON contains `"database_id": null`.
4. On the backend, the dataset API (`superset/datasets/api.py` lines
220–241) uses
`edit_model_schema = DatasetPutSchema()`, and `DatasetPutSchema` is defined
in
`superset/datasets/schemas.py` lines 175–201 with `database_id =
fields.Integer()` (line
177) and no `allow_none=True`. When the request with `"database_id": null`
is validated,
Marshmallow treats `null` as an invalid integer, causing a `ValidationError`
that is
converted to a `SupersetMarshmallowValidationError` by `handle_error` (lines
202–211),
resulting in a SIP-40 error response and a failed dataset save in the UI.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fcomponents%2FDatasource%2FDatasourceModal%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20116%3A116%0A%2A%2AComment%3A%2A%2A%0A%09%2AIntegration%20Bug%3A%20Setting%20%60database_id%60%20to%20%60null%60%20will%20break%20dataset%20saves%20because%20the%20backend%20%60DatasetPutSchema%60%20defines%20%60database_id%60%20as%20an%20integer%20without%20%60allow_none%3DTrue%60%2C%20so%20a%20cleared%20value%20triggers%20request%20validation%20errors.%20Only%20send%20%60database_id%60%20when%20a%20valid%20numeric%20id%20exists%20%28or%20align%20the%20backend%20schema%2Fcommand%20to%20explicitly%20accept%20and%20handle%20nulls%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%
20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fcomponents%2FDatasource%2FDatasourceModal%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20116%3A116%0A%2A%2AComment%3A%2A%2A%0A%09%2AIntegration%20Bug%3A%20Setting%20%60database_id%60%20to%20%60null%60%20will%20break%20dataset%20saves%20because%20the%20backend%20%60DatasetPutSchema%60%20defines%20%60database_id%60%20as%20an%20integer%20without%20%60allow_none%3DTrue%60%2C%20so%20a%20cleared%20value%20triggers%20request%20validation%20errors.%20Only%20send%20%60dat
abase_id%60%20when%20a%20valid%20numeric%20id%20exists%20%28or%20align%20the%20backend%20schema%2Fcommand%20to%20explicitly%20accept%20and%20handle%20nulls%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
*(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/components/Datasource/DatasourceModal/index.tsx
**Line:** 116:116
**Comment:**
*Integration Bug: Setting `database_id` to `null` will break dataset
saves because the backend `DatasetPutSchema` defines `database_id` as an
integer without `allow_none=True`, so a cleared value triggers request
validation errors. Only send `database_id` when a valid numeric id exists (or
align the backend schema/command to explicitly accept and handle nulls).
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%2F39918&comment_hash=5afbd50f7606d08eddcb280d6acdedd9bd73bd3e444f44a9daa0de973d19866b&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39918&comment_hash=5afbd50f7606d08eddcb280d6acdedd9bd73bd3e444f44a9daa0de973d19866b&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]