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
chore(dbc-ui): encode characters before building sqlalchemy uri #17969
Changes from 3 commits
ebaedb6
f3a78be
37f8b1d
8c79758
104897f
e65f2f3
0d03f08
1170ad0
9fcfc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
InvalidParametersError, | ||
) | ||
from superset.databases.dao import DatabaseDAO | ||
from superset.databases.utils import encode_parameters | ||
from superset.db_engine_specs import get_engine_specs | ||
from superset.db_engine_specs.base import BasicParametersMixin | ||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType | ||
|
@@ -99,9 +100,12 @@ def run(self) -> None: | |
except json.decoder.JSONDecodeError: | ||
encrypted_extra = {} | ||
|
||
# encode parameters | ||
params = encode_parameters(self._properties.get("parameters", {})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this value get saved somewhere or is this just for validation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. encode paramaters returns the encode keys in a new dictionary (params) which is used to build the sqlalchemy url a few lines below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hugh, I think the problem is that the validation command doesn't save the database, so the encoding will only apply during validation but not later. You also need to update It might be simpler to implement the encoding logic inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to remove this line now, otherwise we'll end up double encoding the parameters when we call |
||
|
||
# try to connect | ||
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri( # type: ignore | ||
self._properties.get("parameters"), encrypted_extra, | ||
params, encrypted_extra, | ||
) | ||
if self._model and sqlalchemy_uri == self._model.safe_sqlalchemy_uri(): | ||
sqlalchemy_uri = self._model.sqlalchemy_uri_decrypted | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import pytest | ||
|
||
from superset.databases.utils import encode_parameters | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_input, expected", | ||
[ | ||
( | ||
{ | ||
"host": "local%host", | ||
"port": "5432", | ||
"database": "postgres", | ||
"username": "postgres", | ||
"password": "hugh@miles4", | ||
}, | ||
{ | ||
"host": "local%25host", | ||
"port": "5432", | ||
"database": "postgres", | ||
"username": "postgres", | ||
"password": "hugh%40miles4", | ||
}, | ||
) | ||
], | ||
) | ||
def test_escape_parameters(test_input, expected): | ||
assert encode_parameters(test_input) == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hughhhh 90 is already pretty generous, let's keep this as is.