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 7 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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from sqlalchemy.exc import ArgumentError | ||
|
||
from superset import db | ||
from superset.databases.utils import encode_parameters | ||
from superset.db_engine_specs import BaseEngineSpec, get_engine_specs | ||
from superset.exceptions import CertificateException, SupersetSecurityException | ||
from superset.models.core import ConfigurationMethod, Database, PASSWORD_MASK | ||
|
@@ -254,6 +255,10 @@ def build_sqlalchemy_uri( | |
the constructed SQLAlchemy URI to be passed. | ||
""" | ||
parameters = data.pop("parameters", {}) | ||
|
||
# encode parameters | ||
parameters = encode_parameters(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. We also need to add this to DB engine specs that implement their own 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. i added the encode_params to snowflake but, for gsheets and bigquery we don't leverage parameters to build the uri. |
||
|
||
# TODO(AAfghahi) standardize engine. | ||
engine = ( | ||
data.pop("engine", None) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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", | ||
"query": {}, | ||
}, | ||
{ | ||
"host": "local%25host", | ||
"port": "5432", | ||
"database": "postgres", | ||
"username": "postgres", | ||
"password": "hugh%40miles4", | ||
"query": {}, | ||
}, | ||
) | ||
], | ||
) | ||
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.
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 comment
The 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 comment
The 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
DatabaseParametersSchemaMixin
.It might be simpler to implement the encoding logic inside
build_sqlalchemy_uri
. This way it will work with both the validator command and the APIs, and we can have DB-specific encoding logic, which could be needed in the future.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.
We need to remove this line now, otherwise we'll end up double encoding the parameters when we call
build_sqlalchemy_uri
below.