bito-code-review[bot] commented on code in PR #38562:
URL: https://github.com/apache/superset/pull/38562#discussion_r2914158660
##########
tests/unit_tests/mcp_service/test_mcp_tool_registration.py:
##########
@@ -17,25 +17,32 @@
"""Test MCP app imports and tool/prompt registration."""
+import asyncio
+
+
+def _run(coro):
+ """Run an async coroutine synchronously."""
+ return asyncio.get_event_loop().run_until_complete(coro)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Fix deprecated asyncio usage and add type hints</b></div>
<div id="fix">
The _run helper uses deprecated
asyncio.get_event_loop().run_until_complete(), which is problematic in Python
3.10+ as it no longer auto-creates event loops and emits deprecation warnings.
Switch to asyncio.run(coro) for proper synchronous execution of async code.
Also add explicit return type hints per coding standards.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
import asyncio
+from typing import Awaitable, TypeVar
+
+T = TypeVar('T')
+
def _run(coro):
"""Run an async coroutine synchronously."""
return asyncio.get_event_loop().run_until_complete(coro)
@@ -23,3 +26,3 @@
-def _run(coro):
+def _run(coro: Awaitable[T]) -> T:
"""Run an async coroutine synchronously."""
- return asyncio.get_event_loop().run_until_complete(coro)
+ return asyncio.run(coro)
```
</div>
</details>
</div>
<small><i>Code Review Run #4e8a41</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
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -403,26 +396,18 @@ def sanitize_label(cls, v: str | None) -> str | None:
class AxisConfig(BaseModel):
- title: str | None = Field(None, description="Axis title", max_length=200)
- scale: Literal["linear", "log"] | None = Field(
- "linear", description="Axis scale type"
- )
- format: str | None = Field(
- None, description="Format string (e.g. '$,.2f')", max_length=50
- )
+ title: str | None = Field(None, max_length=200)
+ scale: Literal["linear", "log"] | None = "linear"
+ format: str | None = Field(None, description="e.g. '$,.2f'", max_length=50)
class LegendConfig(BaseModel):
- show: bool = Field(True, description="Whether to show legend")
- position: Literal["top", "bottom", "left", "right"] | None = Field(
- "right", description="Legend position"
- )
+ show: bool = True
+ position: Literal["top", "bottom", "left", "right"] | None = "right"
class FilterConfig(BaseModel):
- column: str = Field(
- ..., description="Column to filter on", min_length=1, max_length=255
- )
+ column: str = Field(..., min_length=1, max_length=255)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing column name pattern validation</b></div>
<div id="fix">
FilterConfig.column lacks the pattern validation present in ColumnRef.name,
which could allow invalid column names to pass validation. Since both represent
column names and tests use similar values, add the same pattern to ensure
consistency and prevent potential SQL issues.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
column: str = Field(..., min_length=1, max_length=255,
pattern=r"^[a-zA-Z0-9_][a-zA-Z0-9_\\s\\-\\.]*$")
````
</div>
</details>
</div>
<small><i>Code Review Run #4e8a41</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]