bito-code-review[bot] commented on code in PR #44416:
URL: https://github.com/apache/superset/pull/44416#discussion_r4049663373
##########
superset/commands/chart/update.py:
##########
@@ -203,22 +208,20 @@ def validate(self) -> None: # noqa: C901
# we don't clobber that message with DatasourceTypeInvalidError.
if datasource_type:
try:
- # Slice.datasource only ever resolves the ``table``
- # relationship (see Slice.datasource in
- # superset/models/slice.py), so setting datasource_type to
- # anything else would "succeed" but leave the chart
- # permanently unable to render -- even for a type-only
- # update that leaves datasource_id untouched. Reject those
- # up front instead of failing later -- either at the lookup
- # below (SavedQuery/Query have no ``.name`` attribute, so
- # accessing it raises an unhandled AttributeError) or
- # silently.
- if datasource_type != DatasourceType.TABLE:
- raise DatasourceTypeInvalidError()
- if datasource_id is not None:
- datasource = get_datasource_by_id(datasource_id,
datasource_type)
- self._properties["datasource_name"] = datasource.name
- security_manager.raise_for_access(datasource=datasource)
+ validate_chart_datasource_type(datasource_type)
+ # A type-only change still selects a different datasource
namespace.
+ effective_id: int | None = (
+ datasource_id
+ if "datasource_id" in self._properties
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete null datasource guard</b></div>
<div id="fix">
The null-datasource_id rejection only fires inside `if datasource_type:`
(line 209). When a client sends `datasource_id: null` without
`datasource_type`, that block is skipped, no error is raised, and `run()`
persists the null via `ChartDAO.update` (base.py:548), wiping the chart's
datasource binding. The hardening added here is incomplete for the no-type case.
</div>
</div>
<small><i>Code Review Run #d12fb6</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]