Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 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))
- JS: Ensure imports are sorted ([#865](https://github.com/mozilla/glean_parser/pull/865))
- BREAKING CHANGE: Require pings defined requiring an "ohttp" uploader capability to have `metadata.include_info_sections: false` ([bug 2074263](https://bugzilla.mozilla.org/show_bug.cgi?id=2074263))
- 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))

## 21.0.1

Expand Down
11 changes: 8 additions & 3 deletions glean_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading