bito-code-review[bot] commented on PR #43017:
URL: https://github.com/apache/superset/pull/43017#issuecomment-5508251325
<!-- Bito Reply -->
The suggestion to restrict `_coerce_dataset_id` to strictly integer or
base-10 integer string inputs is appropriate to prevent silent truncation of
floats or unexpected behavior with malformed strings. Using
`int(raw_dataset_id)` as currently implemented allows `1.9` to become `1` and
`"1_0"` to be parsed, which could lead to incorrect dataset references.
To implement this, you can update the helper function to validate the input
format before conversion:
```python
def _coerce_dataset_id(raw_dataset_id: Any) -> Optional[int]:
if isinstance(raw_dataset_id, int):
return raw_dataset_id
if isinstance(raw_dataset_id, str) and raw_dataset_id.isdigit():
return int(raw_dataset_id)
return None
```
Adding a regression test with non-integral values (e.g., `1.9`, `"1.9"`,
`"1_0"`) would ensure that these cases are correctly handled as invalid
references rather than being coerced.
**superset/commands/dashboard/export.py**
```
def _coerce_dataset_id(raw_dataset_id: Any) -> Optional[int]:
if isinstance(raw_dataset_id, int):
return raw_dataset_id
if isinstance(raw_dataset_id, str) and raw_dataset_id.isdigit():
return int(raw_dataset_id)
return None
```
--
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]