fix: DB parameter validation (#14636)
This commit is contained in:
parent
6d9d362ca8
commit
ba5d66cb0a
|
|
@ -278,7 +278,7 @@ class DatabaseValidateParametersSchema(Schema):
|
|||
engine = fields.String(required=True, description="SQLAlchemy engine to use")
|
||||
parameters = fields.Dict(
|
||||
keys=fields.String(),
|
||||
values=fields.Raw(),
|
||||
values=fields.Raw(allow_none=True),
|
||||
description="DB-specific parameters for configuration",
|
||||
)
|
||||
database_name = fields.String(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from collections import defaultdict
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from flask_babel import gettext as _
|
||||
|
|
@ -175,6 +176,11 @@ class InvalidPayloadSchemaError(SupersetErrorException):
|
|||
status = 422
|
||||
|
||||
def __init__(self, error: ValidationError):
|
||||
# dataclasses.asdict does not work with defaultdict, convert to dict
|
||||
# https://bugs.python.org/issue35540
|
||||
for k, v in error.messages.items():
|
||||
if isinstance(v, defaultdict):
|
||||
error.messages[k] = dict(v)
|
||||
error = SupersetError(
|
||||
message="An error happened when validating the request",
|
||||
error_type=SupersetErrorType.INVALID_PAYLOAD_SCHEMA_ERROR,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
"""Unit tests for Superset"""
|
||||
import dataclasses
|
||||
import json
|
||||
from collections import defaultdict
|
||||
from io import BytesIO
|
||||
from unittest import mock
|
||||
from zipfile import is_zipfile, ZipFile
|
||||
|
|
@ -1369,15 +1370,18 @@ class TestDatabaseApi(SupersetTestCase):
|
|||
url = "api/v1/database/validate_parameters"
|
||||
payload = {
|
||||
"engine": "postgresql",
|
||||
"parameters": {
|
||||
"parameters": defaultdict(dict),
|
||||
}
|
||||
payload["parameters"].update(
|
||||
{
|
||||
"host": "",
|
||||
"port": 5432,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": "",
|
||||
"query": {},
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
rv = self.client.post(url, json=payload)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
|
|
@ -1409,15 +1413,18 @@ class TestDatabaseApi(SupersetTestCase):
|
|||
url = "api/v1/database/validate_parameters"
|
||||
payload = {
|
||||
"engine": "postgresql",
|
||||
"parameters": {
|
||||
"parameters": defaultdict(dict),
|
||||
}
|
||||
payload["parameters"].update(
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": "",
|
||||
"query": {},
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
rv = self.client.post(url, json=payload)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue