From b20882f39e66408f56b3cafc0f34e679f13f8071 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Thu, 1 Jul 2021 13:50:31 -0700 Subject: [PATCH] fix: Allow for updates on Step 3 (#15512) * send parameters if they are available * fix bigquery sqlalchem issue * fix casting --- .../DatabaseModal/DatabaseConnectionForm.tsx | 1 + .../data/database/DatabaseModal/index.tsx | 34 +++++++++++++++---- superset/databases/api.py | 5 +++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx index 7310701c41361..9125d4a02ec08 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -173,6 +173,7 @@ const CredentialsInfo = ({ if (event.target.files) { file = event.target.files[0]; } + setFileToUpload(file?.name); changeMethods.onParametersChange({ target: { diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index 411b72d014d16..8dc0d361df800 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -180,7 +180,6 @@ function dbReducer( ...(state || {}), }; let query = ''; - switch (action.type) { case ActionType.extraEditorChange: return { @@ -271,10 +270,13 @@ function dbReducer( ).toString(); } - if (action.payload.backend === 'bigquery') { + if ( + action.payload.backend === 'bigquery' && + action.payload.configuration_method === + CONFIGURATION_METHOD.DYNAMIC_FORM + ) { return { ...action.payload, - encrypted_extra: '', engine: action.payload.backend, configuration_method: action.payload.configuration_method, extra_json: deserializeExtraJSON, @@ -430,9 +432,27 @@ const DatabaseModal: FunctionComponent = ({ const engine = dbToUpdate.backend || dbToUpdate.engine; if (engine === 'bigquery' && dbToUpdate.parameters?.credentials_info) { // wrap encrypted_extra in credentials_info only for BigQuery - dbToUpdate.encrypted_extra = JSON.stringify({ - credentials_info: JSON.parse(dbToUpdate.parameters?.credentials_info), - }); + if ( + dbToUpdate.parameters?.credentials_info && + typeof dbToUpdate.parameters?.credentials_info === 'object' && + dbToUpdate.parameters?.credentials_info.constructor === Object + ) { + // Don't cast if object + dbToUpdate.encrypted_extra = JSON.stringify({ + credentials_info: dbToUpdate.parameters?.credentials_info, + }); + + // Convert credentials info string before updating + dbToUpdate.parameters.credentials_info = JSON.stringify( + dbToUpdate.parameters.credentials_info, + ); + } else { + dbToUpdate.encrypted_extra = JSON.stringify({ + credentials_info: JSON.parse( + dbToUpdate.parameters?.credentials_info, + ), + }); + } } } @@ -648,7 +668,7 @@ const DatabaseModal: FunctionComponent = ({ Finish diff --git a/superset/databases/api.py b/superset/databases/api.py index a0689f4f9a6e9..8e6219fa7988e 100644 --- a/superset/databases/api.py +++ b/superset/databases/api.py @@ -246,6 +246,11 @@ def post(self) -> Response: new_model = CreateDatabaseCommand(g.user, item).run() # Return censored version for sqlalchemy URI item["sqlalchemy_uri"] = new_model.sqlalchemy_uri + + # If parameters are available return them in the payload + if new_model.parameters: + item["parameters"] = new_model.parameters + return self.response(201, id=new_model.id, result=item) except DatabaseInvalidError as ex: return self.response_422(message=ex.normalized_messages())