Skip to content

Commit 040cc1c

Browse files
authored
Merge pull request #315 from pallavibharadwaj/error_handling
feat(data_connector): Parameter check when calling query()
2 parents b88d2bf + 0db7a16 commit 040cc1c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

dataprep/connector/connector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..errors import UnreachableError
1616
from .config_manager import config_directory, ensure_config
17-
from .errors import RequestError, UniversalParameterOverridden
17+
from .errors import RequestError, UniversalParameterOverridden, InvalidParameterError
1818
from .implicit_database import ImplicitDatabase, ImplicitTable
1919
from .int_ref import IntRef
2020
from .throttler import OrderedThrottler, ThrottleSession
@@ -117,6 +117,11 @@ async def query( # pylint: disable=too-many-locals
117117
**where
118118
The additional parameters required for the query.
119119
"""
120+
allowed_params = self._impdb.tables[table].config["request"]["params"]
121+
for key in where:
122+
if key not in allowed_params:
123+
raise InvalidParameterError(key)
124+
120125
return await self._query_imp(table, where, _auth=_auth, _count=_count)
121126

122127
@property

dataprep/connector/errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,18 @@ def __init__(self, param: str, uparam: str) -> None:
4949

5050
def __str__(self) -> str:
5151
return f"the parameter {self.param} is overridden by {self.uparam}"
52+
53+
54+
class InvalidParameterError(Exception):
55+
"""
56+
The parameter used in the query is invalid
57+
"""
58+
59+
param: str
60+
61+
def __init__(self, param: str) -> None:
62+
super().__init__()
63+
self.param = param
64+
65+
def __str__(self) -> str:
66+
return f"the parameter {self.param} is invalid, refer info method"

0 commit comments

Comments
 (0)