diff --git a/CHANGELOG.md b/CHANGELOG.md index 2525aa66..3a2e34ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add a `skip_schema_validation` option to `parse_objects` to skip schema validation of input files ([bug 2076540](https://bugzilla.mozilla.org/show_bug.cgi?id=2076540)) + ## 22.0.0 - JS/TS server: Add support for `server-deletion-request` ping. Server apps can now add `server-deletion-request` to `send_in_pings` on identifier metrics (e.g. user IDs) ([DENG-4079](https://mozilla-hub.atlassian.net/browse/DENG-4079)) diff --git a/glean_parser/parser.py b/glean_parser/parser.py index 98489e3e..7df2d0c9 100644 --- a/glean_parser/parser.py +++ b/glean_parser/parser.py @@ -95,9 +95,10 @@ def _load_file( if filetype not in ("metrics", "pings", "tags"): filetype = None - for error in validate(content, filepath): - content = {} - yield error + if not parser_config.get("skip_schema_validation", False): + for error in validate(content, filepath): + content = {} + yield error return content, filetype @@ -486,6 +487,10 @@ def parse_objects( the input `filepaths` do not exist. - `interesting`: Contains an array of interesting metrics/ping files. Probes not included in these files will be marked as disabled. + - `skip_schema_validation`: Don't validate the input files against the + schema, including checking that `$schema` is a known schema. This is + only safe when they have been validated elsewhere: invalid input may + raise exceptions rather than produce errors. """ if config is None: config = {} diff --git a/tests/test_parser.py b/tests/test_parser.py index 9801add2..040a741c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -727,6 +727,21 @@ def test_do_not_disable_expired(): assert metrics["category"]["metric"].disabled is False +def test_skip_schema_validation(): + contents = [{"category": {"metric": {"type": "boolean", "description": 42}}}] + contents = [util.add_required(x) for x in contents] + + all_metrics = parser.parse_objects(contents) + errors = list(all_metrics) + assert len(errors) == 1 + assert "description" in errors[0] + + all_metrics = parser.parse_objects(contents, {"skip_schema_validation": True}) + errors = list(all_metrics) + assert len(errors) == 0 + assert all_metrics.value["category"]["metric"].description == 42 + + def test_interesting_disables_others(): # Test that if we get an "interesting" config param, only the metrics in # the provided config files are enabled.