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

NodeShape constraints aren't enforced #572

Open
dpetran opened this issue Sep 13, 2023 · 4 comments
Open

NodeShape constraints aren't enforced #572

dpetran opened this issue Sep 13, 2023 · 4 comments
Labels
bug Something isn't working as expected

Comments

@dpetran
Copy link
Contributor

dpetran commented Sep 13, 2023

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 dpetran added the bug Something isn't working as expected label Sep 13, 2023
@JaceRockman
Copy link
Contributor

@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?

@dpetran
Copy link
Contributor Author

dpetran commented May 6, 2024

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.

@JaceRockman
Copy link
Contributor

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.

@dpetran
Copy link
Contributor Author

dpetran commented May 6, 2024

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

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

No branches or pull requests

2 participants