Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed May 12, 2021
1 parent 0a70331 commit 2ec1375
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 44 deletions.
2 changes: 1 addition & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def _try_json_readsha( # pylint: disable=unused-argument

# Default row limit for SQL Lab queries. Is overridden by setting a new limit in
# the SQL Lab UI
DEFAULT_SQLLAB_LIMIT = 1000
DEFAULT_SQLLAB_LIMIT = 10000

# Maximum number of tables/views displayed in the dropdown window in SQL Lab.
MAX_TABLE_NAMES = 3000
Expand Down
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
DatabaseFunctionNamesResponse,
DatabaseRelatedObjectsResponse,
DatabaseTestConnectionSchema,
DatabaseValidateParametersSchema,
TableMetadataResponseSchema,
SelectStarResponseSchema,
SchemasResponseSchema,
Expand Down
5 changes: 3 additions & 2 deletions superset/databases/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from superset.db_engine_specs import get_engine_specs
from superset.db_engine_specs.base import BaseParametersMixin
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.exceptions import SupersetErrorException, SupersetErrorsException
from superset.models.core import Database


Expand Down Expand Up @@ -83,7 +82,9 @@ def run(self) -> None:
raise InvalidParametersError(errors)

# try to connect
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri(self._properties) # type: ignore
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri(
self._properties["parameters"] # type: ignore
)
if self._model and sqlalchemy_uri == self._model.safe_sqlalchemy_uri():
sqlalchemy_uri = self._model.sqlalchemy_uri_decrypted
database = DatabaseDAO.build_db_for_connection_test(
Expand Down
1 change: 1 addition & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
CONNECTION_INVALID_PASSWORD_NEEDED_REGEX: (
__("Please re-enter the password."),
SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR,
{"invalid": ["password"]},
),
CONNECTION_INVALID_HOSTNAME_REGEX: (
__('The hostname "%(hostname)s" cannot be resolved.'),
Expand Down
3 changes: 2 additions & 1 deletion superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ class SupersetErrorType(str, Enum):
{
"code": 1018,
"message": _(
"Issue 1018 - One or more parameters needed to configure a database are missing."
"Issue 1018 - One or more parameters needed to configure a "
"database are missing."
),
},
],
Expand Down
21 changes: 17 additions & 4 deletions tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ def test_available(self, app, get_available_engine_specs):
},
"query": {
"additionalProperties": {},
"description": "Additinal parameters",
"description": "Additional parameters",
"type": "object",
},
"username": {
Expand All @@ -1299,7 +1299,7 @@ def test_available(self, app, get_available_engine_specs):
"type": "string",
},
},
"required": ["database", "host", "port"],
"required": ["database", "host", "port", "username"],
"type": "object",
},
"preferred": True,
Expand All @@ -1322,7 +1322,14 @@ def test_validate_parameters_invalid_payload_format(self):
"message": "Request is not JSON",
"error_type": "INVALID_PAYLOAD_FORMAT_ERROR",
"level": "error",
"extra": {},
"extra": {
"issue_codes": [
{
"code": 1019,
"message": "Issue 1019 - The submitted payload has the incorrect format.",
}
]
},
}
]
}
Expand All @@ -1345,7 +1352,13 @@ def test_validate_parameters_invalid_payload_schema(self):
"messages": {
"engine": ["Missing data for required field."],
"foo": ["Unknown field."],
}
},
"issue_codes": [
{
"code": 1020,
"message": "Issue 1020 - The submitted payload has the incorrect schema.",
}
],
},
}
]
Expand Down
23 changes: 11 additions & 12 deletions tests/databases/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,15 @@ def test_connection_db_api_exc(self, mock_event_logger, mock_get_sqla_engine):
mock_event_logger.assert_called()


def test_validate(app_context):
@mock.patch("superset.db_engine_specs.base.is_hostname_valid")
@mock.patch("superset.db_engine_specs.base.is_port_open")
@mock.patch("superset.databases.commands.validate.DatabaseDAO")
def test_validate(DatabaseDAO, is_port_open, is_hostname_valid, app_context):
"""
Test parameter validation.
Currently only supported in Postgres.
"""
database = get_example_database()
if database.backend != "postgresql":
return
is_hostname_valid.return_value = True
is_port_open.return_value = True

payload = {
"engine": "postgresql",
Expand All @@ -649,15 +649,14 @@ def test_validate(app_context):
command.run()


def test_validate_partial(app_context):
@mock.patch("superset.db_engine_specs.base.is_hostname_valid")
@mock.patch("superset.db_engine_specs.base.is_port_open")
def test_validate_partial(is_port_open, is_hostname_valid, app_context):
"""
Test parameter validation when only some parameters are present.
Currently only supported in Postgres.
"""
database = get_example_database()
if database.backend != "postgresql":
return
is_hostname_valid.return_value = True
is_port_open.return_value = True

payload = {
"engine": "postgresql",
Expand Down
19 changes: 9 additions & 10 deletions tests/db_engine_specs/base_engine_spec_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def test_limit_query_with_limit_subquery(self): # pylint: disable=invalid-name

def test_limit_query_without_force(self):
self.sql_limit_regex(
"SELECT * FROM a LIMIT 10",
"SELECT * FROM a LIMIT 10",
limit=11,
"SELECT * FROM a LIMIT 10", "SELECT * FROM a LIMIT 10", limit=11,
)

def test_limit_query_with_force(self):
Expand Down Expand Up @@ -361,11 +359,7 @@ def test_get_time_grain_with_unkown_values():
config = app.config.copy()

app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
"mysql": {
"PT2H": "foo",
"weird": "foo",
"PT12H": "foo",
}
"mysql": {"PT2H": "foo", "weird": "foo", "PT12H": "foo",}
}

with app.app_context():
Expand Down Expand Up @@ -464,6 +458,11 @@ def test_validate_parameters_port_closed(is_port_open, is_hostname_valid):
message="The port is closed.",
error_type=SupersetErrorType.CONNECTION_PORT_CLOSED_ERROR,
level=ErrorLevel.ERROR,
extra={"invalid": ["host", "port"]},
),
extra={
"invalid": ["port"],
"issue_codes": [
{"code": 1008, "message": "Issue 1008 - The port is closed."}
],
},
)
]
27 changes: 13 additions & 14 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,20 @@ def test_extract_errors(self):
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR,
message="Please re-enter the password.",
error_type=SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR,
level=ErrorLevel.ERROR,
extra={
"invalid": ["password"],
"engine_name": "PostgreSQL",
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the"
" username or the password is wrong.",
"message": "Issue 1014 - Either the username or the password is wrong.",
},
{
"code": 1015,
"message": "Issue 1015 - Either the database is "
"spelled incorrectly or does not exist.",
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
},
],
},
Expand Down Expand Up @@ -445,20 +444,20 @@ def test_base_parameters_mixin():
assert json_schema == {
"type": "object",
"properties": {
"port": {
"type": "integer",
"format": "int32",
"description": "Database port",
},
"password": {"type": "string", "nullable": True, "description": "Password"},
"host": {"type": "string", "description": "Hostname or IP address"},
"username": {"type": "string", "nullable": True, "description": "Username"},
"password": {"type": "string", "nullable": True, "description": "Password"},
"database": {"type": "string", "description": "Database name"},
"query": {
"type": "object",
"description": "Additinal parameters",
"description": "Additional parameters",
"additionalProperties": {},
},
"port": {
"type": "integer",
"format": "int32",
"description": "Database port",
},
"database": {"type": "string", "description": "Database name"},
},
"required": ["database", "host", "port"],
"required": ["database", "host", "port", "username"],
}

0 comments on commit 2ec1375

Please sign in to comment.