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

subjects used as predicates don't have iris in query results #521

Closed
dpetran opened this issue Jul 5, 2023 · 5 comments · Fixed by #563
Closed

subjects used as predicates don't have iris in query results #521

dpetran opened this issue Jul 5, 2023 · 5 comments · Fixed by #563
Assignees
Labels
bug Something isn't working as expected
Milestone

Comments

@dpetran
Copy link
Contributor

dpetran commented Jul 5, 2023

If a subject is created in one transaction and then used as a predicate in another transaction, the query will fail to translate the predicate id into an iri.

(let [conn   @(fluree/connect {:method :memory})
        ledger @(fluree/create conn "propertypathstest" {:defaultContext [test-utils/default-str-context {"ex" "http://example.com/"}]})
        db0    (fluree/db ledger)
        db1    @(fluree/stage db0 [{"@id" "ex:preexisting-pred"
                                     "ex:description" "created as a subject first"}])
        db2 @(fluree/stage db1 [{"@id" "ex:subject-as-predicate"
                                     "ex:preexisting-pred" "foo"
                                     "ex:new-pred" "bar"}])]
  @(fluree/query db2 {"select" {"?s" ["*"]}
                                   "where" [["?s" "@id" "ex:subject-as-predicate"]]}))
;; actual
{"id" "ex:subject-as-predicate",
 "ex:new-pred" "bar",
  211106232532992 "foo"}
;; expected
{"id" "ex:subject-as-predicate",
 "ex:new-pred" "bar",
 "ex:preexisting-pred" "foo"}
@dpetran dpetran added the bug Something isn't working as expected label Jul 5, 2023
@dpetran
Copy link
Contributor Author

dpetran commented Jul 5, 2023

This is due to how we find vocab flakes. On each transaction we check the new flakes for vocab flakes. That is done by checking if any new flakes have a subject in the "predicate" range. A subject that is created without being used as a predicate is assigned a subject id in the general "subject" range, and so it doesn't trigger a vocab/refresh-schema call.

We need some sort of general way of telling when we have new vocabulary that won't degrade performance, since we do this vocabulary check in a lot of places.

@dpetran
Copy link
Contributor Author

dpetran commented Jul 5, 2023

We do have a workaround in the case where we know/suspect a given iri will be used as a predicate in the future. In those cases we can add the predefined pid to the fluree.db.json-ld.ledger/generate-new-sid function. It's not a general solution though and something more robust is necessary to handle unexpected subjects-as-predicates.

@aaj3f aaj3f added this to the 3.0.0-beta2 milestone Aug 19, 2023
@aaj3f
Copy link
Contributor

aaj3f commented Aug 19, 2023

@aaj3f
Copy link
Contributor

aaj3f commented Aug 19, 2023

Moved to top of backlog as it impacts integration of FlureeSense data output into v3

@dpetran dpetran self-assigned this Aug 21, 2023
dpetran added a commit that referenced this issue Aug 23, 2023
Before this commit each selector used the iri-cache differently, and therefore gave
broken results if they were combined in a scenario that required iri lookups.

This normalizes the cache structure by making every cache update insert an entry in the
form of `(vswap! iri-cache assoc pid {:as <iri>})`, so that every cache read can use the
results regardless of where it was first inserted.

The other fix in this commit is adding a `dbproto/-iri` lookup to the
`response/wildcard-spec` function. Before it would return a raw pid in the response,
which is unhelpful for users.

fixes #521
dpetran added a commit that referenced this issue Aug 23, 2023
Before this commit each selector used the iri-cache differently, and therefore gave
broken results if they were combined in a scenario that required iri lookups.

This normalizes the cache structure by making every cache update insert an entry in the
form of `(vswap! iri-cache assoc pid {:as <iri>})`, so that every cache read can use the
results regardless of where it was first inserted.

The other fix in this commit is adding a `dbproto/-iri` lookup to the
`response/wildcard-spec` function. Before it would return a raw pid in the response,
which is unhelpful for users.

fixes #521
@aaj3f
Copy link
Contributor

aaj3f commented Aug 25, 2023

@dpetran -- just want to confirm that you saw this message in Slack

Before we close this, I just want to confirm that this behavior (at least against http-api-gateway) is still seeing properties that are inserted via nested JSON-LD are still returning integers instead of IRIs in query results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants