mirror of
https://github.com/apache/superset.git
synced 2026-05-30 04:39:20 +00:00
fix(sql-lab): correct createCtasDatasource return type and fix latent bug
Address codeant/bito review on #40037. The /api/v1/dataset/get_or_create/ endpoint returns { result: { table_id: number } } per its OpenAPI schema, but createCtasDatasource was annotated as Promise<{ id: number }> and passed json.result straight into createDatasourceSuccess (which builds `${data.id}__table`). The result.id read was always undefined, so the CTAS Explore flow has been silently constructing "undefined__table" as the datasource identifier at runtime. The previous as-unknown-as cast in ExploreCtasResultsButton hid the contract drift from TypeScript. - createCtasDatasource now returns Promise<{ table_id: number }>, matching the actual API payload. - Normalize result.table_id -> { id } when dispatching createDatasourceSuccess, so the existing reducer/action contract is preserved (createDatasource still calls it with a real { id }). - Drop the cast in ExploreCtasResultsButton; data.table_id is now properly type-checked. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1712,7 +1712,7 @@ export function createDatasource(
|
||||
|
||||
export function createCtasDatasource(
|
||||
vizOptions: Record<string, unknown>,
|
||||
): SqlLabThunkAction<Promise<{ id: number }>> {
|
||||
): SqlLabThunkAction<Promise<{ table_id: number }>> {
|
||||
return (dispatch: AppDispatch) => {
|
||||
dispatch(createDatasourceStarted());
|
||||
return SupersetClient.post({
|
||||
@@ -1720,9 +1720,14 @@ export function createCtasDatasource(
|
||||
jsonPayload: vizOptions,
|
||||
})
|
||||
.then(({ json }) => {
|
||||
dispatch(createDatasourceSuccess(json.result));
|
||||
const result = json.result as { table_id: number };
|
||||
// The endpoint's `result.table_id` IS the dataset id; normalize so
|
||||
// createDatasourceSuccess's `${data.id}__table` resolves correctly.
|
||||
// Without this, the CTAS Explore button silently produced
|
||||
// `"undefined__table"` because `result.id` doesn't exist.
|
||||
dispatch(createDatasourceSuccess({ id: result.table_id }));
|
||||
|
||||
return json.result;
|
||||
return result;
|
||||
})
|
||||
.catch(() => {
|
||||
const errorMsg = t('An error occurred while creating the data source');
|
||||
|
||||
@@ -56,11 +56,7 @@ const ExploreCtasResultsButton = ({
|
||||
};
|
||||
|
||||
const visualize = () => {
|
||||
(
|
||||
dispatch(createCtasDatasource(buildVizOptions)) as unknown as Promise<{
|
||||
table_id: number;
|
||||
}>
|
||||
)
|
||||
dispatch(createCtasDatasource(buildVizOptions))
|
||||
.then(data => {
|
||||
const formData = {
|
||||
datasource: `${data.table_id}__table`,
|
||||
|
||||
Reference in New Issue
Block a user