fluree / db

Fluree database library

Home Page:https://fluree.github.io/db/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NodeShape constraints aren't enforced

dpetran opened this issue · comments

If we place constraints directly on a sh:NodeShape, instead of nested under a sh:property, the constraints are not enforced.

;; example shape
{"@id" "ex:friendShape"
  "@type" ["sh:NodeShape"]
   "sh:targetObjectsOf" {"@id" "ex:birthdate"}
   "sh:datatype" {"@id" "xsd:date"}
    "sh:maxCount" 1}

;; example transaction
{"@id" "ex:Bob"
  "ex:birthdate" "May 1, 2000"}

This transaction passes without any validation errors when it should raise a sh:datatype constraint violation.

@dpetran I can't get the sh:datatype constraint violation to fire even when I do use sh:property. Could this be an issue with sh:targetObjectsOf more generally?

sh:datatype constraints are a little tricky because we use them for coercion. So if we're unable to coerce a value to the constrained datatype you would get a coercion error instead of a validation error.

The way to get around this is to use @type on the value to bypass coercion.

;; example transaction that bypasses coercion
{"@id" "ex:Bob"
  "ex:birthdate" {"@type" "xsd:string" "@value" "May 1, 2000"}

This should be fixed with the new SHACL error messages, but it would be good to verify.

So when I transact

{"ledger" ledger-name
  "insert" [{"@type"              "sh:NodeShape"
                   "sh:targetObjectsOf" {"@id" "ex:birthdate"}
                   "sh:property"        {"sh:datatype" {"@id" "xsd:date"}
                                                   "sh:maxCount" 1}}]}

and

{"ledger" ledger-name
  "insert" [{"@id"          "ex:Bob"
                   "ex:birthdate" {"@type" "xsd:string" "@value" "May 1, 2000"}}]}

Or am I missing something? I'm just having trouble getting it to produce an error at anypoint.

If it's not producing an error then it's still a bug.