diff --git a/backend/src/appenlight/tests/test_unit.py b/backend/src/appenlight/tests/test_unit.py index ace3685..245d438 100644 --- a/backend/src/appenlight/tests/test_unit.py +++ b/backend/src/appenlight/tests/test_unit.py @@ -1498,6 +1498,7 @@ class TestAPISentryView(object): request = pyramid.threadlocal.get_current_request() context = DummyContext() context.resource = ApplicationService.by_id(1) + context.resource.allow_permanent_storage = True request.context = context request.matched_route = route request.body = b'eJy1UmFr2zAQ/S0T+7BCLOzYThp/C6xjG6SDLd/GCBf57Ki' \ @@ -1537,6 +1538,7 @@ class TestAPISentryView(object): }) context = DummyContext() context.resource = ApplicationService.by_id(1) + context.resource.allow_permanent_storage = True request.context = context request.matched_route = route request.body = SENTRY_RUBY_ENCODED @@ -1556,6 +1558,7 @@ class TestAPISentryView(object): request = pyramid.threadlocal.get_current_request() context = DummyContext() context.resource = ApplicationService.by_id(1) + context.resource.allow_permanent_storage = True request.context = context request.matched_route = route request.body = json.dumps(SENTRY_PYTHON_PAYLOAD_7).encode('utf8') @@ -1583,6 +1586,7 @@ class TestAPISentryView(object): }) context = DummyContext() context.resource = ApplicationService.by_id(1) + context.resource.allow_permanent_storage = True request.context = context request.matched_route = route request.body = SENTRY_PYTHON_ENCODED diff --git a/backend/src/appenlight/validators.py b/backend/src/appenlight/validators.py index 811a0fa..31aeff9 100644 --- a/backend/src/appenlight/validators.py +++ b/backend/src/appenlight/validators.py @@ -50,6 +50,12 @@ def deferred_utcnow(node, kw): return kw['utcnow'] +@colander.deferred +def optional_limited_date(node, kw): + if not kw.get('allow_permanent_storage'): + return limited_date + + def lowercase_preparer(input_data): """ Transforms a list of string entries to lowercase @@ -292,9 +298,11 @@ class ReportDetailBaseSchema(colander.MappingSchema): preparer=shortener_factory(1024), missing='') ip = colander.SchemaNode(colander.String(), preparer=shortener_factory(39), missing=None) - start_time = colander.SchemaNode(NonTZDate(), validator=limited_date, + start_time = colander.SchemaNode(NonTZDate(), + validator=optional_limited_date, missing=deferred_utcnow) - end_time = colander.SchemaNode(NonTZDate(), validator=limited_date, + end_time = colander.SchemaNode(NonTZDate(), + validator=optional_limited_date, missing=None) user_agent = colander.SchemaNode(colander.String(), preparer=[shortener_factory(512), diff --git a/backend/src/appenlight/views/api.py b/backend/src/appenlight/views/api.py index b894413..dc949fc 100644 --- a/backend/src/appenlight/views/api.py +++ b/backend/src/appenlight/views/api.py @@ -428,7 +428,9 @@ def sentry_compat(request): len(non_pkey_logs))) tasks.add_logs.delay(application.resource_id, {}, non_pkey_logs) if event_type == ParsedSentryEventType.ERROR_REPORT: - schema = ReportSchema_0_5().bind(utcnow=datetime.datetime.utcnow()) + schema = ReportSchema_0_5().bind( + utcnow=datetime.datetime.utcnow(), + allow_permanent_storage=application.allow_permanent_storage) deserialized_reports = [schema.deserialize(event)] rate_limiting(request, application, 'per_application_reports_rate_limit',