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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -395,6 +396,44 @@ def _normalize_group_by_input(v: Any) -> Any:
     return v
 
 
+def _get_known_fields(model_class: type[BaseModel]) -> set[str]:
+    """Collect all valid field names including validation aliases."""
+    known: set[str] = set()
+    for field_name, field_info in model_class.model_fields.items():
+        known.add(field_name)
+        alias = field_info.validation_alias
+        if isinstance(alias, AliasChoices):
+            for choice in alias.choices:
+                if isinstance(choice, str):
+                    known.add(choice)

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incomplete validation alias handling</b></div>
   <div id="fix">
   
   The _get_known_fields function only checks for AliasChoices when processing 
validation_alias, but Pydantic v2 also supports string aliases. This means 
string validation aliases are not added to the known fields set, causing them 
to be incorrectly treated as unknown fields during validation. Update the 
function to also handle isinstance(alias, str) cases.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
           alias = field_info.validation_alias
           if isinstance(alias, str):
               known.add(alias)
           elif isinstance(alias, AliasChoices):
               for choice in alias.choices:
                   if isinstance(choice, str):
                       known.add(choice)
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #e24329</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