Skip to content
Snippets Groups Projects
Commit c3ead4ad authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

Merge branch 'f-casting-transformers' into ruqad

parents dddf26d9 716ec67e
Branches
Tags
1 merge request!217TST: Make NamedTemporaryFiles Windows-compatible
Pipeline #59612 passed
......@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ZipFileConverter that opens zip files and exposes their contents as
File and Directory structure elements.
- `linkahead-crawler` script as alias for `caosdb-crawler`.
- New transformers of the form `cast_to_*` which allow casting variables to `int`, `float`,
`str` and `bool`.
### Changed ###
......
......@@ -123,12 +123,14 @@ def convert_record(record: db.Record):
return _apply_schema_patches(pobj)
def validate(records: list[db.Record], schemas: dict[str, dict]) -> list[tuple[bool, list]]:
def validate(records: list[db.Record], schemas: dict[str, dict]) -> list[tuple]:
"""
Validate a list of records against a list of possible JSON schemas.
It is tried to validate each schema from the list of schemas. If none of them validates
without error, it is assumed that it does not match at all.
Validate a list of records against a dictionary of schemas.
The keys of the dictionary are record types and the corresponding values are json schemata
associated with that record type. The current implementation assumes that each record that is
checked has exactly one parent and raises an error if that is not the case.
The schema belonging to a record is identified using the name of the first (and only) parent
of the record.
Arguments:
----------
......@@ -136,15 +138,16 @@ def validate(records: list[db.Record], schemas: dict[str, dict]) -> list[tuple[b
records: list[db.Record]
List of records that will be validated.
schemas: list[dict]
A list of JSON schemas generated using `load_json_schema_from_datamodel_yaml`.
schemas: dict[str, dict]
A dictionary of JSON schemas generated using `load_json_schema_from_datamodel_yaml`.
Returns:
--------
A list of tuples, one element for each record:
- Index 0: A boolean that determines whether at least one schema matched for this record.
- Index 1: A list of schemas matching the record at this position of the list `records`.
- Index 0: A boolean that determines whether the schema belonging to the record type of the
record matched.
- Index 1: A validation error if the schema did not match or None otherwise.
"""
retval = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment