dosubot[bot] commented on issue #29968:
URL: https://github.com/apache/superset/issues/29968#issuecomment-2296353488
<!-- Answer -->
To resolve the error "Sorry, there was an error saving this dashboard:
[object Object]" when setting the `refresh_frequency` parameter in your JSON
Metadata, ensure that the `refresh_frequency` is correctly set and passed in
the `metadata` object within the `saveDashboardRequest` function.
Here is the relevant part of the code that handles the `refresh_frequency`:
```js
const refreshFrequency = shouldPersistRefreshFrequency
? currentRefreshFrequency
: dashboardInfo.metadata?.refresh_frequency; // eslint-disable camelcase
const data = {
certified_by: dashboardInfo.certified_by,
certification_details: dashboardInfo.certification_details,
css: customCss,
dashboard_title:
saveType === SAVE_TYPE_NEWDASHBOARD ? newDashName : dashboardTitle,
duplicate_slices: this.state.duplicateSlices,
last_modified_time: lastModifiedTime,
owners: dashboardInfo.owners,
roles: dashboardInfo.roles,
metadata: {
...dashboardInfo?.metadata,
positions,
refresh_frequency: refreshFrequency,
},
};
```
Make sure that `refresh_frequency` is a valid number and is correctly
included in the `metadata` object. If `refresh_frequency` is not properly set,
it might cause the error you are encountering.
Additionally, ensure that the `saveDashboardRequest` function handles errors
appropriately. Here is the relevant part of the error handling code:
```js
const onError = async response => {
const { error, message } = await getClientErrorObject(response);
let errorText = t('Sorry, an unknown error occurred');
if (error) {
errorText = t(
'Sorry, there was an error saving this dashboard: %s',
error,
);
}
if (typeof message === 'string' && message === 'Forbidden') {
errorText = t('You do not have permission to edit this dashboard');
}
dispatch(saveDashboardFinished());
dispatch(addDangerToast(errorText));
};
```
This ensures that any errors encountered during the save operation are
properly reported, which can help in diagnosing issues with the
`refresh_frequency` parameter.
Moreover, you can use the `RefreshIntervalModal` component to set the
`refresh_frequency` parameter correctly. Here is an example of how the
`RefreshIntervalModal` component handles the refresh interval:
```tsx
class RefreshIntervalModal extends PureComponent<
RefreshIntervalModalProps,
RefreshIntervalModalState
> {
// ... other methods and state initialization
handleFrequencyChange(value: number) {
const { refreshIntervalOptions } = this.props;
this.setState({
refreshFrequency: value || refreshIntervalOptions[0][0],
});
this.setState({
custom_block: value === -1,
});
if (value === -1) {
this.setState({
custom_hour: 0,
custom_min: 0,
custom_sec: 0,
});
}
}
// ... other methods and render function
}
```
Ensure that the `refreshFrequency` state is updated correctly and passed to
the `onChange` function when saving the interval. This will help in setting the
`refresh_frequency` parameter correctly in the JSON Metadata.
Additionally, based on the integration tests provided, ensure that the
`json_metadata` field is correctly formatted and valid. For example, the
following test case shows how `json_metadata` should be structured:
```py
dashboard_data = {
"dashboard_title": "title1_changed",
"slug": "slug1_changed",
"position_json": '{"b": "B"}',
"css": "css_changed",
"json_metadata": '{"refresh_frequency": 30,
"timed_refresh_immune_slices": [], "expanded_slices": {}, "color_scheme": "",
"label_colors": {}, "shared_label_colors": {}, "color_scheme_domain": [],
"cross_filters_enabled": false}',
"published": False,
}
```
Ensure that `refresh_frequency` is a valid number within the `json_metadata`
and that the entire JSON structure is correctly formatted. This will help in
avoiding errors when saving the dashboard
<sup>[[1]](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/components/SaveModal.tsx)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/actions/dashboardState.js)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx)</sup><sup>[[4]](https://github.com/apache/superset/blob/master/tests/integration_tests/dashboards/api_tests.py)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]