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

fix: queryGraph selection for query and update #2546

Merged
merged 2 commits into from
Aug 29, 2023

Conversation

aucampia
Copy link
Member

Summary of changes

Store.query and Store.update have a parameter queryGraph, which
presumably specifies the initial active
graph
.

When SPARQL is evaluated against a Dataset, the initial active graph
should be the default graph
[ref],
however, when calling rdflib.graph.Graph.query or
rdflib.graph.Graph.update, they were passing
rdflib.graph.Dataset.identifier as the value of queryGraph to
Store.query and Store.update. The passed value would not have been
the identifier of the default graph of the Dataset, and would instead
have been an identifier that has really no meaning whatsoever (see
#2537).

This change fixes the selection of the initial active graph by passing
ConjunctiveGraph.default_context.identifier if the Graph.query or
Graph.update method is called on a ConjunctiveGraph and
ConjunctiveGraph.default_union is False.

Related issues:

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Checked that all tests and type checking passes.
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

@aucampia aucampia requested a review from a team August 26, 2023 20:37
@aucampia aucampia added the review wanted This indicates that the PR is ready for review label Aug 26, 2023
`Store.query` and `Store.update` have a parameter `queryGraph`, which
presumably specifies the initial [active
graph](https://www.w3.org/TR/sparql11-query/#sparqlDataset).

When SPARQL is evaluated against a `Dataset`, the initial active graph
should be the default graph
[[ref](https://www.w3.org/TR/sparql11-query/#sparqlAlgebraEval)],
however, when calling `rdflib.graph.Graph.query` or
`rdflib.graph.Graph.update`, they were passing
`rdflib.graph.Dataset.identifier` as the value of `queryGraph` to
`Store.query` and `Store.update`. The passed value would not have been
the identifier of the default graph of the Dataset, and would instead
have been an identifier that has really no meaning whatsoever (see
<RDFLib#2537>).

This change fixes the selection of the initial active graph by passing
`ConjunctiveGraph.default_context.identifier` if the `Graph.query` or
`Graph.update` method is called on a `ConjunctiveGraph` and
`ConjunctiveGraph.default_union` is `False`.

Related issues:
- Fixes <RDFLib#2538>.
@aucampia aucampia force-pushed the aucampia/20230826T1203-fix-store-query branch from 92b4181 to 9b9686e Compare August 26, 2023 20:38
@aucampia aucampia added SPARQL store Related to a store. labels Aug 26, 2023
@aucampia
Copy link
Member Author

After this oxigraph/oxrdflib#28 should hopefully not be a thing.

@coveralls
Copy link

coveralls commented Aug 26, 2023

Coverage Status

coverage: 90.94%. first build when pulling 478b56b on aucampia:aucampia/20230826T1203-fix-store-query into e757687 on RDFLib:main.

@aucampia aucampia added the ready to merge The PR will be merged soon if no further feedback is provided. label Aug 26, 2023
@aucampia
Copy link
Member Author

The other option is to make Dataset.identifier the same as Dataset.default_context.identifier - that may actually be somewhat sensible 🤔

@aucampia
Copy link
Member Author

The other option is to make Dataset.identifier the same as Dataset.default_context.identifier - that may actually be somewhat sensible 🤔

Maybe starting with this PR is best, we can change to having Dataset.identifier the same as Dataset.default_context.identifier later and then just adjust the behaviour here if needs be.

Copy link
Contributor

@Tpt Tpt left a comment

Choose a reason for hiding this comment

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

Thank you! It fixes oxrdflib

@aucampia
Copy link
Member Author

Thank you! It fixes oxrdflib

Thank you for having a look

@aucampia aucampia merged commit 077f4ac into RDFLib:main Aug 29, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR will be merged soon if no further feedback is provided. review wanted This indicates that the PR is ready for review SPARQL store Related to a store.
Projects
None yet
3 participants