Skip to content
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

Adding the option of using POST for queries in SPARQLStore #673

Merged
merged 3 commits into from
Dec 5, 2016

Conversation

SeguinBe
Copy link
Contributor

@SeguinBe SeguinBe commented Dec 2, 2016

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('<VERY LONG STRING>')
# 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('<VERY LONG STRING>')
# Works!

Tiny changes based on postAsEncoded param in SPARQLUpdateStore

Copy link
Member

@joernhees joernhees left a comment

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,
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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)

@joernhees joernhees added enhancement New feature or request in-resolution SPARQL store Related to a store. labels Dec 4, 2016
@joernhees joernhees added this to the rdflib 4.2.2 milestone Dec 4, 2016
@SeguinBe
Copy link
Contributor Author

SeguinBe commented Dec 4, 2016

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.

default is set on init, actual query method might be changed during exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in-resolution SPARQL store Related to a store.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants