bito-code-review[bot] commented on PR #43556:
URL: https://github.com/apache/superset/pull/43556#issuecomment-5427377543
<!-- Bito Reply -->
The suggestion is valid. The current implementation of
`get_dataset_id_from_context` assumes `payload` and `payload.get("datasource")`
are dictionaries, which can lead to `AttributeError` or `TypeError` if the
request body contains unexpected values (e.g., `null` or non-dictionary types).
To resolve this, you should normalize the input by ensuring the values are
dictionaries before accessing them:
```python
if payload := get_request_json_body():
datasource = payload.get("datasource")
if isinstance(datasource, dict) and (dataset_id :=
datasource.get("id")):
return dataset_id
form_data.update(payload.get("form_data") if
isinstance(payload.get("form_data"), dict) else {})
```
There are no other comments on this PR to address. Would you like me to
implement this fix for you?
**superset/jinja_context.py**
```
if payload := get_request_json_body():
datasource = payload.get("datasource")
if isinstance(datasource, dict) and (dataset_id :=
datasource.get("id")):
return dataset_id
form_data.update(payload.get("form_data") if
isinstance(payload.get("form_data"), dict) else {})
```
--
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]