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

Schema-based check assignment for compiled release and dataset checks #12

Open
jpmckinney opened this issue May 5, 2021 · 2 comments
Open
Labels
Milestone

Comments

@jpmckinney
Copy link
Member

jpmckinney commented May 5, 2021

Field-level checks are explicitly assigned to each field. This means that, if the OCDS schema changes, or if extensions are used, then definitions.py will need to be updated. Instead, it's possible to determine which checks to perform on which fields, by inspecting the OCDS release schema.

There is also hard-coding of paths to period objects in period_duration_in_days.py and period.py, and of paths to value objects in value_realistic.py (and a bunch more).

  • coherent.milestone_status
@jpmckinney
Copy link
Member Author

For rules like "For any field (or array item) with "$ref": "#/definitions/Identifier"":

In other OCDS code, we run jsonref.JsonRef.replace_refs(schema), loop through the schema and, if a path matches a condition, we yield it as a tuple. Then, we loop through the data. If a path in the data matches a path from the schema (we need to remove array indices from the data’s path in order to match the schema’s path, e.g. (‘contracts’, 0, ‘id’) becomes (‘contracts’, ‘id’)), then we perform an operation.

@jpmckinney
Copy link
Member Author

jpmckinney commented Oct 29, 2021

For field-level definitions, I compared my calculated definitions (x) to the existing definitions with:

print(set(x) - set(definitions))
print(set(definitions) - set(x))

for k in set(x) & set(definitions):
    if x[k] != definitions[k] and (
        # Empty
        not x[k]
        # Non-partial
        or not any(hasattr(v[0], "func") for v in x[k])
        # Partial: functools.partial(foo, "bar") != functools.partial(foo, "bar")
        or any(
            x[k][i][1] != definitions[k][i][1]
            or x[k][i][0].func != definitions[k][i][0].func
            or x[k][i][0].args != definitions[k][i][0].args
            or x[k][i][0].keywords != definitions[k][i][0].keywords
            for i in range(len(x[k]))
        )
    ):
        print(k)
        print(x[k])
        print(definitions[k])

jpmckinney added a commit that referenced this issue Oct 29, 2021
The change to the fixture is due to the corrections in 2f0fd89
@jpmckinney jpmckinney added this to the Cleanup milestone Jan 17, 2023
@jpmckinney jpmckinney changed the title Schema-based check assignment Schema-based check assignment for compiled release and dataset checks Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant