Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dashboard import holding issue #19112

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ export function useImportResource(
t(
'An error occurred while importing %s: %s',
resourceLabel,
error.errors.map(payload => payload.message).join('\n'),
[
...error.errors.map(payload => payload.message),
'Please re-export your file and try importing again',
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
].join('\n'),
),
);
} else {
Expand All @@ -464,7 +467,7 @@ export function useImportResource(
updateState({ loading: false });
});
},
[],
[handleErrorMsg, resourceLabel, resourceName],
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
);

return { state, importResource };
Expand Down
25 changes: 25 additions & 0 deletions superset-frontend/src/views/CRUD/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ const terminalErrors = {
],
};

const terminalErrorsWithOnlyIssuesCode = {
errors: [
{
message: 'Error importing database',
error_type: 'GENERIC_COMMAND_ERROR',
level: 'warning',
extra: {
issue_codes: [
{
code: 1010,
message:
'Issue 1010 - Superset encountered an error while running a command.',
},
],
},
},
],
};

const overwriteNeededErrors = {
errors: [
{
Expand Down Expand Up @@ -146,6 +165,12 @@ test('detects if the error message is terminal or if it requires uses interventi
expect(isTerminal).toBe(false);
});

test('error message is terminal when the extra field not contains other keys excepting issue_codes', () => {
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
expect(hasTerminalValidation(terminalErrorsWithOnlyIssuesCode.errors)).toBe(
true,
);
});

test('does not ask for password when the import type is wrong', () => {
const error = {
errors: [
Expand Down
20 changes: 11 additions & 9 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,17 @@ export const getAlreadyExists = (errors: Record<string, any>[]) =>
.flat();

export const hasTerminalValidation = (errors: Record<string, any>[]) =>
errors.some(
error =>
!Object.entries(error.extra)
.filter(([key, _]) => key !== 'issue_codes')
.every(
([_, payload]) =>
isNeedsPassword(payload) || isAlreadyExists(payload),
),
);
errors.some(error => {
const not_issues_codes = Object.entries(error.extra).filter(
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
([key, _]) => key !== 'issue_codes',
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
);

if (not_issues_codes.length === 0) return true;

return !not_issues_codes.every(
([_, payload]) => isNeedsPassword(payload) || isAlreadyExists(payload),
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
);
});

export const checkUploadExtensions = (
perm: Array<any> | string | undefined | boolean,
Expand Down