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


##########
superset/databases/schemas.py:
##########
@@ -906,7 +939,10 @@ def fix_schemas_allowed_for_csv_upload(  # pylint: 
disable=invalid-name
 
     metadata_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
     engine_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
-    metadata_cache_timeout = fields.Dict(keys=fields.Str(), 
values=fields.Integer())
+    metadata_cache_timeout = fields.Dict(
+        keys=fields.Str(),
+        values=fields.Integer(validate=Range(min=0)),
+    )

Review Comment:
   **Suggestion:** This import schema now rejects `metadata_cache_timeout: 
null` because the dict field does not allow `None`, while the API validator 
path currently accepts `null`; that creates an API/import contract mismatch 
where a database config accepted and exported by one path can fail on import. 
Align both paths by either disallowing `null` everywhere or allowing and 
normalizing it consistently. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Exported database configs with null timeout cannot import.
   - ⚠️ Assets export/import pipeline becomes non-round-trippable.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Create or update a database through the REST API (`POST 
/api/v1/database/` / `PUT
   /api/v1/database/<id>` using `DatabasePostSchema` / `DatabasePutSchema`) 
with Extra JSON
   containing `"metadata_cache_timeout": null`; `extra_validator` in
   `superset/databases/schemas.py:254-309` accepts this value because it treats 
`None` as an
   empty dict locally (`superset/databases/schemas.py:281-283`) and returns the 
original
   string unchanged, so the database is stored with `metadata_cache_timeout` 
set to null.
   
   2. Export all assets using `GET /api/v1/assets/export/` handled by
   `ImportExportRestApi.export` (`superset/importexport/api.py:46-83`), which 
invokes
   `ExportAssetsCommand` to serialize databases into YAML; the exported 
database config will
   include `extra` as a mapping with `"metadata_cache_timeout": null` 
reflecting the
   persisted state.
   
   3. Import the same bundle via `POST /api/v1/assets/import/` 
(`ImportExportRestApi.import_`
   in `superset/importexport/api.py:95-200`), which uses `ImportAssetsCommand`
   (`superset/commands/importers/v1/assets.py:59-73`) and its `schemas` mapping 
to validate
   database files against `ImportV1DatabaseSchema` 
(`superset/databases/schemas.py:79-123`),
   where `extra` is a nested `ImportV1DatabaseExtraSchema`.
   
   4. During import, `ImportV1DatabaseExtraSchema.metadata_cache_timeout`
   (`superset/databases/schemas.py:61-66`) is a `fields.Dict` whose values are
   `fields.Integer(validate=Range(min=0))` and the field does not allow `None` 
for the
   top-level mapping; when it encounters `metadata_cache_timeout: null` from 
the exported
   config, marshmallow raises a `ValidationError`, causing the database asset 
import to fail
   even though the configuration was originally accepted and exported by the 
API.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a74392afa27541e6a132354bed77fd4d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a74392afa27541e6a132354bed77fd4d&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/databases/schemas.py
   **Line:** 942:945
   **Comment:**
        *Api Mismatch: This import schema now rejects `metadata_cache_timeout: 
null` because the dict field does not allow `None`, while the API validator 
path currently accepts `null`; that creates an API/import contract mismatch 
where a database config accepted and exported by one path can fail on import. 
Align both paths by either disallowing `null` everywhere or allowing and 
normalizing it consistently.
   
   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%2F38490&comment_hash=e0a7c9777dfd17a297cd4893a813db971d42b5e3bb047af9a34f9f1db78e8714&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38490&comment_hash=e0a7c9777dfd17a297cd4893a813db971d42b5e3bb047af9a34f9f1db78e8714&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