Skip to content

Commit

Permalink
feat(data_connector): Parameter check when calling query()
Browse files Browse the repository at this point in the history
raises an exception when invalid parameters are passed to the query method

closes #267
  • Loading branch information
pallavibharadwaj committed Sep 11, 2020
1 parent c1fea00 commit 0db7a16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dataprep/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ..errors import UnreachableError
from .config_manager import config_directory, ensure_config
from .errors import RequestError, UniversalParameterOverridden
from .errors import RequestError, UniversalParameterOverridden, InvalidParameterError
from .implicit_database import ImplicitDatabase, ImplicitTable
from .int_ref import IntRef
from .throttler import OrderedThrottler, ThrottleSession
Expand Down Expand Up @@ -117,6 +117,11 @@ async def query( # pylint: disable=too-many-locals
**where
The additional parameters required for the query.
"""
allowed_params = self._impdb.tables[table].config["request"]["params"]
for key in where:
if key not in allowed_params:
raise InvalidParameterError(key)

return await self._query_imp(table, where, _auth=_auth, _count=_count)

@property
Expand Down
15 changes: 15 additions & 0 deletions dataprep/connector/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ def __init__(self, param: str, uparam: str) -> None:

def __str__(self) -> str:
return f"the parameter {self.param} is overridden by {self.uparam}"


class InvalidParameterError(Exception):
"""
The parameter used in the query is invalid
"""

param: str

def __init__(self, param: str) -> None:
super().__init__()
self.param = param

def __str__(self) -> str:
return f"the parameter {self.param} is invalid, refer info method"

0 comments on commit 0db7a16

Please sign in to comment.