Understanding issues

The Issue class

One Issue corresponds to one failed check on one field in the properties. An Issue has three attributes:

  • type: The type of the check that failed and caused the issue. This can be a type that exists in the Data Package standard (e.g., required or pattern) or a custom type.
  • jsonpath: The JSON path of the field that failed the check. For example, $.resources[2].name.
  • message: An explanation of what went wrong.

The explain() function

The explain() function provides a more verbose and user-friendly description of a list of Issues. To use it, pass it the issues output by check():

import check_datapackage as cdp

package_properties = {
    "name": 123,
    "title": "Hibernation Physiology of the Woolly Dormouse: A Scoping Review.",
    "id": "123-abc-123",
    "created": "2014-05-14T05:00:01+00:00",
    "version": "1.0.0",
    "licenses": [{"name": "odc-pddl"}],
}

cdp.check(properties=package_properties)
[Issue(jsonpath='$.name', type='type', message="123 is not of type 'string'"),
 Issue(jsonpath='$.resources', type='required', message="'resources' is a required property")]

When setting error=True in check(), error messages will be generated by the explain() function.