bito-code-review[bot] commented on code in PR #40376:
URL: https://github.com/apache/superset/pull/40376#discussion_r3299564213


##########
superset/commands/dataset/importers/v1/__init__.py:
##########
@@ -69,4 +73,11 @@ def _import(
                 and config["database_uuid"] in database_ids
             ):
                 config["database_id"] = database_ids[config["database_uuid"]]
-                import_dataset(config, overwrite=overwrite)
+                try:
+                    import_dataset(config, overwrite=overwrite)
+                except MultiCatalogDisabledValidationError as ex:
+                    # surface as a 422 validation error instead of a generic 
500
+                    raise CommandInvalidError(
+                        "; ".join(str(message) for message in ex.messages),

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>CWE-20: Wrong dict key iteration</b></div>
   <div id="fix">
   
   The iteration `for message in ex.messages` iterates over dict keys (field 
names like 'catalog'), not the actual error messages. In marshmallow 3.x, 
`ValidationError.messages` is a dict with values being lists of error strings. 
Should use `for msgs in ex.messages.values() for msg in msgs` to flatten the 
structure, similar to existing pattern at 
`superset/commands/importers/v1/utils.py:97`. (See also: 
[CWE-20](https://cwe.mitre.org/data/definitions/20.html))
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    --- superset/commands/dataset/importers/v1/__init__.py
    +++ superset/commands/dataset/importers/v1/__init__.py
    @@ -78,4 +78,8 @@
                         raise CommandInvalidError(
    -                        "; ".join(str(message) for message in ex.messages),
    +                        "; ".join(
    +                            str(msg)
    +                            for msgs in ex.messages.values()
    +                            for msg in msgs
    +                        ),
                             [ex],
                         ) from ex
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #ce8b5d</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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