Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Big Query Error messaging #15334

Merged
merged 6 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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