fluree / core

Fluree releases and public bug reports
0 stars 0 forks source link

insert and delete variables are expanded with `@base` `@vocab` contexts #53

Open dpetran opened 7 months ago

dpetran commented 7 months ago

When a transaction has a context that defines @base and @vocab, variables within the the insert and delete clauses get erroneously expanded:

(json-ld/expand {"@context" {"@base" "ex:ns/" "@vocab" ""}
                 "@id" "?s"
                 "foo" "bar"})
;;=>
{:idx [], :id "ex:ns/?s", "ex:ns/foo" [{:value "bar", :type nil, :idx ["foo"]}]}
;; note the "ex:ns/?s" id instead of just "?s"

We need to avoid expanding these variables so they can be parsed correctly.

Here are three possible approaches:

  1. make json-ld/expand aware of variables so it can skip expanding them
  2. make the variables valid iris so they won't get captured by @base
  3. don't json-ld/expand at all, manually traverse the tree and call expand-iri where we want it (like how we do where-clause parsing)

json-ld/expand cannot handle variable symbols either, with the same possible solutions.

dpetran commented 7 months ago

After discussing with Ben, we're going to go with option 3.

aaj3f commented 5 months ago

Relevant comments & examples provided by @Jackamus29 in this thread: https://fluree-internal.slack.com/archives/C04AA19P3FW/p1706296205125759?thread_ts=1706294773.772209&cid=C04AA19P3FW

Jackamus29 commented 5 months ago

Here's another case may be fixed when this ticket is resolved:

Description delete+where doesn't work if @vocab is present.

Steps to Reproduce

  1. Create ledger with data

    {
    "ledger": "vocab-test",
    "@context": {
    "@vocab": "https://flur.ee/"
    },
    "insert": [
    {
      "@id": "freddy",
      "@type": "Yeti",
      "name": "Freddy"
    }
    ]
    }
  2. Delete subject

    {
    "ledger": "vocab-test",
    "@context": {
    "@vocab": "https://flur.ee/"
    },
    "where": {
    "@id": "freddy",
    "?p": "?o"
    },
    "delete": {
    "@id": "freddy",
    "?p": "?o"
    }
    }
  3. History query shows no retractions

    {
    "from": "vocab-test",
    "commit-details": true,
    "t": {
    "at": "latest"
    },
    "@context": {
    "@vocab": "https://flur.ee/",
    "f": "https://ns.flur.ee/ledger#"
    }
    }

    and query shows the subject

    {
    "from": "vocab-test",
    "select": {
    "freddy": [
      "*"
    ]
    }
    }

    =>

    [
    {
    "@id": "freddy",
    "@type": "https://flur.ee/Yeti",
    "https://flur.ee/name": "Freddy"
    }
    ]