Adding the option of using POST for queries in SPARQLStore by SeguinBe · Pull Request #673 · RDFLib/rdflib (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation5 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

SeguinBe

Solution to #672

Just adding a small parameter to be able to use POST for queries in order to to perform long requests.

Previously :

graph = Graph('SPARQLUpdateStore', identifier='http://localhost:8890/WGA') graph.query('')

Query get cropped because it's done with HTTP GET

Now :

from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore store = sparqlstore.SPARQLUpdateStore(query_as_post=True) graph = Graph(store, identifier='http://localhost:8890/WGA') graph.query('')

Works!

Tiny changes based on postAsEncoded param in SPARQLUpdateStore

@SeguinBe

joernhees

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR... slight change request:
i think this is more "stable" long term... might be interesting to have an automatic failover for too long GETs somewhen...

@@ -239,6 +239,7 @@ def __init__(self,
sparql11=True, context_aware=True,
node_to_sparql=_node_to_sparql,
node_from_result=_node_from_result,
query_as_post=False,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rename this to default_query_method=GET?

@@ -259,6 +260,7 @@ def __init__(self,
self.context_aware = context_aware
self.graph_aware = context_aware
self._timeout = None
self.query_as_post = query_as_post

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.query_method = default_query_method

@@ -322,6 +324,7 @@ def query(self, query,
" ".join(self.node_to_sparql(initBindings[x]) for x in v))
self.resetQuery()
self.setMethod(POST if self.query_as_post else GET)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.setMethod(self.query_method)

@SeguinBe

@SeguinBe

Yeah having something automatic might be good for users, because the current error message is really not hepful right now (complains about a weird character).

Also, it should be noted that this extension doesn't allow to make a POST query with the sparql query as POST data directly. By default it uses an URL_ENCODED scheme. Not sure if it might be useful at one point though.

@joernhees

default is set on init, actual query method might be changed during exec

This was referenced

Mar 16, 2017

2 participants

@SeguinBe @joernhees