RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
241 stars 63 forks source link

`_evaluation_path` length is not configurable #224

Closed crisely09 closed 2 months ago

crisely09 commented 3 months ago

We have been dealing with problems validating complex schemas because 30 is still a small path for us to traverse. It would be incredibly helpful if the _evaluation_path limit was another parameter in the validate method.

ashleysommer commented 3 months ago

Thanks @crisely09 for raising this.

The length of 30 was chosen because it was the shortest evaluation_path length that allowed the most complex test in the PySHACL test suite to still pass. We found that SHACL evaluations more complex than that were extremely unlikely to be deliberately run by a user. By setting it to 30, we found that was a good way to expose unintended evaluation loops and other Shape targeting issues in the SHACL Shapes file, while still allowing shapes without issues to run unhindered.

Having said that, I can see that making it a configurable option makes sense, it would allow those with a legitimate use case to set it to whichever level they require.

I will add it to the list of changes for the next release.

ashleysommer commented 2 months ago

Hi @crisely09 This is feature is now added in PySHACL v0.26.0

If you're using pyshacl on the commandline, you can pass --max-depth i where i is 1 to 999. If you're using pyshacl as a library, you can use the validate() argument max_validation_depth.

Note, the depth is now calculated differently than before. The "validation depth" is now defined as the total number of Shapes in the evaluation path, where it was previously calculated as total (Shapes + Constraints) on the evaluation path. Practically, that means "validation depth" is now half the recorded _evaluation_path length, so the default configured "validation depth" is 15, that matches the previous max "evaluation_path" length of 30.

So keep that in mind when setting a higher max depth limit.

crisely09 commented 2 months ago

Hi @ashleysommer , This is great news, I will keep in mind the meaning of the "validation depth", thanks a lot!