Skip to content

Commit

Permalink
encoded parameters in build sqla
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh committed Jan 10, 2022
1 parent e65f2f3 commit 0d03f08
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Expand Up @@ -45,7 +45,6 @@ repos:
hooks:
- id: black
language_version: python3
args: ['--line-length', '90']
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.4.1 # Use the sha or tag you want to point at
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -364,7 +364,7 @@ max-args=5
ignored-argument-names=_.*

# Maximum number of locals for function / method body
max-locals=15
max-locals=16

# Maximum number of return / yield for function / method body
max-returns=10
Expand Down
5 changes: 4 additions & 1 deletion superset/databases/commands/validate.py
Expand Up @@ -100,9 +100,12 @@ def run(self) -> None:
except json.decoder.JSONDecodeError:
encrypted_extra = {}

# encode parameters
params = encode_parameters(self._properties.get("parameters", {}))

# try to connect
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri( # type: ignore
self._properties.get("parameters", {}), encrypted_extra,
params, encrypted_extra,
)
if self._model and sqlalchemy_uri == self._model.safe_sqlalchemy_uri():
sqlalchemy_uri = self._model.sqlalchemy_uri_decrypted
Expand Down
5 changes: 5 additions & 0 deletions superset/databases/schemas.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

# TODO(AAfghahi) standardize engine.
engine = (
data.pop("engine", None)
Expand Down
16 changes: 6 additions & 10 deletions superset/utils/async_query_manager.py
Expand Up @@ -167,16 +167,16 @@ def parse_jwt_from_request(self, req: Request) -> Dict[str, Any]:

def init_job(self, channel_id: str, user_id: Optional[str]) -> Dict[str, Any]:
job_id = str(uuid.uuid4())
return build_job_metadata(channel_id, job_id, user_id, status=self.STATUS_PENDING)
return build_job_metadata(
channel_id, job_id, user_id, status=self.STATUS_PENDING
)

def read_events(
self, channel: str, last_id: Optional[str]
) -> List[Optional[Dict[str, Any]]]:
stream_name = f"{self._stream_prefix}{channel}"
start_id = increment_id(last_id) if last_id else "-"
results = self._redis.xrange( # type: ignore
stream_name, start_id, "+", self.MAX_EVENT_COUNT
)
results = self._redis.xrange(stream_name, start_id, "+", self.MAX_EVENT_COUNT)
return [] if not results else list(map(parse_event, results))

def update_job(
Expand All @@ -197,9 +197,5 @@ def update_job(
logger.debug("********** logging event data to stream %s", scoped_stream_name)
logger.debug(event_data)

self._redis.xadd( # type: ignore
scoped_stream_name, event_data, "*", self._stream_limit
)
self._redis.xadd( # type: ignore
full_stream_name, event_data, "*", self._stream_limit_firehose
)
self._redis.xadd(scoped_stream_name, event_data, "*", self._stream_limit)
self._redis.xadd(full_stream_name, event_data, "*", self._stream_limit_firehose)

0 comments on commit 0d03f08

Please sign in to comment.