From d0eb6bea9504e1fdd0c0925ae9f1def648bf0a7b Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Thu, 19 Sep 2024 11:20:08 +0200 Subject: [PATCH] Validation: ignore the '_meta' property we've observed that this is sent-in-practice. we don't want to actually remove it from the stored data, so we remove it only from the thing we validate (not the actual data) --- ingest/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ingest/views.py b/ingest/views.py index 2d0fb8f..b1594da 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -132,15 +132,17 @@ class BaseIngestAPIView(View): # ValidatorClass.check_schema(event_schema) cls._event_validator = ValidatorClass(event_schema) + data_to_validate = {k: v for k, v in data.items() if k != "_meta"} + if validation_setting == "strict": try: - cls._event_validator.validate(data) + cls._event_validator.validate(data_to_validate) except jsonschema.ValidationError as e: raise ValidationError(understandable_json_error(e), code="invalid_event_data") from e else: # "warn" try: - cls._event_validator.validate(data) + cls._event_validator.validate(data_to_validate) except jsonschema.ValidationError as e: logger.warn("event data validation failed: %s", understandable_json_error(e))