From 863600c0d527d11c90930b51403a18d40a63800c Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Tue, 14 Dec 2021 08:07:01 -0800 Subject: [PATCH] fix: import DB errors --- .../src/views/CRUD/utils.test.tsx | 28 +++++++++++++++++++ superset-frontend/src/views/CRUD/utils.tsx | 9 ++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.test.tsx b/superset-frontend/src/views/CRUD/utils.test.tsx index 24cb0ce97fc23..2b95319d85d5b 100644 --- a/superset-frontend/src/views/CRUD/utils.test.tsx +++ b/superset-frontend/src/views/CRUD/utils.test.tsx @@ -143,3 +143,31 @@ test('detects if the error message is terminal or if it requires uses interventi isTerminal = hasTerminalValidation(passwordNeededErrors.errors); expect(isTerminal).toBe(false); }); + +test('does not ask for password when the import type is wrong', () => { + const error = { + errors: [ + { + message: 'Error importing database', + error_type: 'GENERIC_COMMAND_ERROR', + level: 'warning', + extra: { + 'metadata.yaml': { + type: ['Must be equal to Database.'], + }, + 'databases/examples.yaml': { + _schema: ['Must provide a password for the database'], + }, + issue_codes: [ + { + code: 1010, + message: + 'Issue 1010 - Superset encountered an error while running a command.', + }, + ], + }, + }, + ], + }; + expect(hasTerminalValidation(error.errors)).toBe(true); +}); diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index f261e1cd69c6b..64a92e08c63de 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -373,7 +373,10 @@ export const getAlreadyExists = (errors: Record[]) => export const hasTerminalValidation = (errors: Record[]) => errors.some( error => - !Object.values(error.extra).some( - payload => isNeedsPassword(payload) || isAlreadyExists(payload), - ), + !Object.entries(error.extra) + .filter(([key, _]) => key !== 'issue_codes') + .every( + ([_, payload]) => + isNeedsPassword(payload) || isAlreadyExists(payload), + ), );