-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query Sanity Checking #116
Comments
Note: Currently, it is not entirely clear to me, where exactly this logic should run. Options are e.g.
This would ensure that the query gets checked as soon as possible. Also model sanity checking according to #108 could run in the initializer, so query and model checking would both happen in one place and as soon as possible. class SPARQLModelAdapter(Generic[_TModelInstance]):
# ...
def __init__(
self, target: str | SPARQLWrapper, query: str, model: type[_TModelInstance]
) -> None:
self._query = get_checked_query(query)
self._model = get_checked_model(model)
# ...
This would encapsulate all query logic in a single class and would also communicate clearly, that |
The change introduces a check_query callable which runs an extensible compose pipeline of query checkers. The check_query function runs in SPARQLModelAdapter to enable fast failures on inapplicable queries; also a run_query_check=False flag is added to the QueryConstructor class so that QueryConstructor could also be used as a standalone class with query checking enabled. Closes #116.
The change introduces a check_query callable which runs an extensible compose pipeline of query checkers. Note regarding QueryParseException: This custom exception is intended to be a thin wrapper around a pyparsing ParseException that RDFLib raises. This avoids introducing pyparsing as a dependency just to be able to test against this exception. I feel like RDFLib should not raise a pyparsing exception but provide a thin wrapper itself. See RDFLib/rdflib#3057. The check_query function runs in SPARQLModelAdapter to enable fast failures on inapplicable queries; also a run_query_check=False flag is added to the QueryConstructor class so that QueryConstructor could also be used as a standalone class with query checking enabled. Closes #116.
The change introduces a check_query callable which runs an extensible compose pipeline of query checkers. Note regarding QueryParseException: This custom exception is intended to be a thin wrapper around a pyparsing ParseException that RDFLib raises. This avoids introducing pyparsing as a dependency just to be able to test against this exception. I feel like RDFLib should not raise a pyparsing exception but provide a thin wrapper itself. See RDFLib/rdflib#3057. The check_query function runs in SPARQLModelAdapter to enable fast failures on inapplicable queries. Note that this somewhat couples QueryConstructor to SPARQLModelAdapter; QueryConstructor should be marked private for this reason. Closes #116.
The change introduces a check_query callable which runs an extensible compose pipeline of query checkers. Note regarding QueryParseException: This custom exception is intended to be a thin wrapper around a pyparsing ParseException that RDFLib raises. This avoids introducing pyparsing as a dependency just to be able to test against this exception. I feel like RDFLib should not raise a pyparsing exception but provide a thin wrapper itself. See RDFLib/rdflib#3057. The check_query function runs in SPARQLModelAdapter to enable fast failures on inapplicable queries. Note that this somewhat couples QueryConstructor to SPARQLModelAdapter; QueryConstructor should be marked private for this reason. Closes #116.
rdfproxy
should run certain checks on queries to fail as fast as possible in case of inapplicable queries to avoid inadvertent side effects or simply crashing later in the program flow.It might be advisable to parse incoming queries with an external parsing tool which raise
ParsingExceptions
early.Note that the
rdflib
SPARQL parser is not fully reliable for this, see #2960.rdflib.plugins.sparql.parser.parseQuery
can however catch SPARQL syntax errors.rdfproxy
is designed to handle SELECT queries, passing anything but a SELECT query to aSPARQLModelAdapter
will certainly crash (somewhere) but still might have inadvertent side effects.So passing anything but a SELECT query should crash the program as fast as possible.
A SELECT query predicate can be defined using the
rdflib
SPARQL parser plugin:Another option would be to use
SPARQLWrapper
internals for determining the query type (seeSPARQLWrapper.Wrapper._parseQueryType
l597) or to utilize the compiled regex patternSPARQLWrapper.pattern
(seeSPARQLWrapper.SPARQLWrapper
l267)I prefer the
rdflib
solution.See #126.
The text was updated successfully, but these errors were encountered: