bito-code-review[bot] commented on code in PR #31929:
URL: https://github.com/apache/superset/pull/31929#discussion_r2934357517
##########
superset/commands/chart/create.py:
##########
@@ -43,6 +43,15 @@ class CreateChartCommand(CreateMixin, BaseCommand):
def __init__(self, data: dict[str, Any]):
self._properties = data.copy()
+ if self._properties.get('params'):
+ try:
+ import json
+ params = json.loads(self._properties['params'])
+ if 'viz_type' in params:
+ self._properties['viz_type'] = params['viz_type']
+ except json.JSONDecodeError as ex:
+ raise ex
+
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>TypeError risk on non-dict params</b></div>
<div id="fix">
The code checks for 'viz_type' in params without verifying params is a dict.
Since params is validated as valid JSON, it could be a string, number, or
array, causing a TypeError. It looks like params is intended to be an object,
but to prevent runtime errors, add a type check.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- superset/commands/chart/create.py
+++ superset/commands/chart/create.py
@@ -46,7 +46,7 @@
if self._properties.get('params'):
try:
import json
params = json.loads(self._properties['params'])
- if 'viz_type' in params:
+ if isinstance(params, dict) and 'viz_type' in params:
self._properties['viz_type'] = params['viz_type']
except json.JSONDecodeError as ex:
raise ex
```
</div>
</details>
</div>
<small><i>Code Review Run #99b817</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]