Skip to content

Commit

Permalink
fix: Allow for updates on Step 3 (#15512)
Browse files Browse the repository at this point in the history
* send parameters if they are available

* fix bigquery sqlalchem issue

* fix casting
  • Loading branch information
hughhhh authored Jul 1, 2021
1 parent 4fc5589 commit b20882f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const CredentialsInfo = ({
if (event.target.files) {
file = event.target.files[0];
}

setFileToUpload(file?.name);
changeMethods.onParametersChange({
target: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function dbReducer(
...(state || {}),
};
let query = '';

switch (action.type) {
case ActionType.extraEditorChange:
return {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -430,9 +432,27 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
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,
),
});
}
}
}

Expand Down Expand Up @@ -648,7 +668,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
<StyledFooterButton
key="submit"
buttonStyle="primary"
onClick={onClose}
onClick={onSave}
data-test="modal-confirm-button"
>
Finish
Expand Down
5 changes: 5 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit b20882f

Please sign in to comment.