From 1ee476f05abf06cc6eeb19ad74882daaa5d10573 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Fri, 26 Apr 2024 11:28:36 +0200 Subject: [PATCH] abort storing transcript if previous version is missing --- server/cp/signals.py | 17 ++++++++++++++--- server/tests/test_signals.py | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/cp/signals.py b/server/cp/signals.py index e3d111c..5344570 100644 --- a/server/cp/signals.py +++ b/server/cp/signals.py @@ -1,4 +1,5 @@ import cp +import flask from typing import Literal, Optional from flask import current_app as app @@ -67,6 +68,11 @@ def on_push(sender, item, **kwargs): if item.get("language"): item["language"] = fix_language(item["language"]) + if get_media_type(item) and item.get("evolvedfrom"): + parent_item = get_resource_service("items").find_one(req=None, _id=item["evolvedfrom"]) + if parent_item is None: + flask.abort(503) # must be 50x error to trigger retry later + def user_auth_is_gip(user: User) -> bool: if not user.get("company"): @@ -81,12 +87,17 @@ def user_auth_is_gip(user: User) -> bool: return company.get("auth_provider") == "gip" -def handle_transcripts(item): - item.setdefault("subject", []) +def get_media_type(item): media_type_scheme = get_media_type_scheme() - media_type = next( + return next( (s for s in item["subject"] if s.get("scheme") == media_type_scheme), None ) + + +def handle_transcripts(item): + item.setdefault("subject", []) + media_type_scheme = get_media_type_scheme() + media_type = get_media_type(item) media_source_scheme = app.config.get("MEDIA_SOURCE_SCHEME", "station") media_source = next( (s for s in item["subject"] if s.get("scheme") == media_source_scheme), None diff --git a/server/tests/test_signals.py b/server/tests/test_signals.py index 980adf3..05d0332 100644 --- a/server/tests/test_signals.py +++ b/server/tests/test_signals.py @@ -172,7 +172,7 @@ def test_cem_notification_for_non_google_auth(app, mocker): assert len(sub.mock_calls) == 0 -def test_language_agenda(): +def test_language_agenda(app): item = {"language": "en-CA"} signals.init_app(None) signals.push.send(None, item=item)