Skip to content

Commit

Permalink
fix: Big Query Error messaging (#15334)
Browse files Browse the repository at this point in the history
* remove validation check

* remove validation check

* fix error messaging

* stop validation on big query

* add condition for skipping specific engines for validation

* if no params
  • Loading branch information
hughhhh authored Jun 23, 2021
1 parent 725f406 commit c64ad88
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ function dbReducer(
if (action.payload.backend === 'bigquery') {
return {
...action.payload,
engine: trimmedState.engine,
encrypted_extra: '',
engine: action.payload.backend,
configuration_method: action.payload.configuration_method,
extra_json: deserializeExtraJSON,
parameters: {
Expand Down
11 changes: 8 additions & 3 deletions superset/databases/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.models.core import Database

BYPASS_VALIDATION_ENGINES = ["bigquery"]


class ValidateDatabaseParametersCommand(BaseCommand):
def __init__(self, user: User, parameters: Dict[str, Any]):
Expand All @@ -45,6 +47,11 @@ def __init__(self, user: User, parameters: Dict[str, Any]):
def run(self) -> None:
engine = self._properties["engine"]
engine_specs = get_engine_specs()

if engine in BYPASS_VALIDATION_ENGINES:
# Skip engines that are only validated onCreate
return

if engine not in engine_specs:
raise InvalidEngineError(
SupersetError(
Expand Down Expand Up @@ -78,9 +85,7 @@ def run(self) -> None:
)

# perform initial validation
errors = engine_spec.validate_parameters(
self._properties.get("parameters", None)
)
errors = engine_spec.validate_parameters(self._properties.get("parameters", {}))
if errors:
raise InvalidParametersError(errors)

Expand Down
17 changes: 8 additions & 9 deletions superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from apispec.ext.marshmallow import MarshmallowPlugin
from flask_babel import gettext as __
from marshmallow import fields, Schema
from marshmallow.exceptions import ValidationError
from sqlalchemy import literal_column
from sqlalchemy.engine.url import make_url
from sqlalchemy.sql.expression import ColumnClause
Expand All @@ -32,7 +33,6 @@
from superset.databases.schemas import encrypted_field_properties, EncryptedField
from superset.db_engine_specs.base import BaseEngineSpec
from superset.errors import SupersetError, SupersetErrorType
from superset.exceptions import SupersetGenericDBErrorException
from superset.sql_parse import Table
from superset.utils import core as utils
from superset.utils.hashing import md5_sha_from_str
Expand Down Expand Up @@ -317,15 +317,16 @@ def build_sqlalchemy_uri(
) -> str:
query = parameters.get("query", {})
query_params = urllib.parse.urlencode(query)
if encrypted_extra:
project_id = encrypted_extra.get("credentials_info", {}).get("project_id")

if not encrypted_extra:
raise ValidationError("Missing service credentials")

project_id = encrypted_extra.get("credentials_info", {}).get("project_id")

if project_id:
return f"{cls.default_driver}://{project_id}/?{query_params}"

raise SupersetGenericDBErrorException(
message="Big Query encrypted_extra is not available.",
)
raise ValidationError("Invalid service credentials")

@classmethod
def get_parameters_from_uri(
Expand All @@ -337,9 +338,7 @@ def get_parameters_from_uri(
if encrypted_extra:
return {**encrypted_extra, "query": value.query}

raise SupersetGenericDBErrorException(
message="Big Query encrypted_extra is not available.",
)
raise ValidationError("Invalid service credentials")

@classmethod
def validate_parameters(
Expand Down

0 comments on commit c64ad88

Please sign in to comment.