ADR 0004 — The field schema is read with Frictionless¶
Status: accepted. It supersedes the way ADR 0003 reads the schema file and holds its fields, and where that decision puts the download cache. The rest of ADR 0003 stands.
Decision¶
ghfdb/fields/schema.json is read by Frictionless, and the package uses Frictionless’s own types.
load_schema()passes the file tofrictionless.Schema.from_descriptorand returns thefrictionless.Schema. ghfdb defines no field class and no schema class. The facts Table Schema has no property for (published column name, obligation, domain, quality relevance, unit and the rest) stay in each field’scustomdictionary, where Frictionless keeps them and writes them back.A vocabulary field’s
vocabularyobject is read as written in the file. There is no class for it.What Frictionless cannot do stays in this repository: resolving each vocabulary field’s allowed values from the vocabularies into the field’s
enumconstraint, in memory only, and finding a field by its published column name (field_for_column). A field is found by its code with Frictionless’sget_field, and the complete schema is the loaded schema, written withto_descriptor()orto_json().AllowedValuestays, as a small frozen type, because Table Schema has no place for the label, URI and notation of an allowed value and the field reference links every term to its concept.The download cache is the
vocabulariesdirectory inplatformdirs.user_cache_dir("ghfdb"), or the directory passed tocaching_session. TheGHFDB_VOCABULARY_CACHEenvironment variable is gone: nothing but the tests used it, and they pass a directory.The field reference is rendered from Jinja2 templates, and the tests stand in for the web with
responses.frictionless,platformdirsand (for the documentation)jinja2are declared dependencies.
Why¶
CONSTITUTION.md Articles II and VII prefer an established, maintained package to custom code and
rule a package’s size out as a reason against it. The first version of the field schema read the
file with json into frozen dataclasses that restated the Frictionless types, on the ground that
Frictionless was a large dependency. That put a loader, three classes and a lookup table in this
repository to keep in step with a file that Frictionless already reads, validates and writes
back. A field added to the schema meant a change to the file and a change to the classes. With
Frictionless’s types there is one place to change.
The functions that work on a frictionless.Schema are module-level because the type is not ours to
extend. A class wrapping it would be the restatement this decision removes.
Revisit if¶
Frictionless stops keeping unknown field properties in custom, or Table Schema gains a place for
the label and URI of each allowed value, which would remove AllowedValue.