Skip to content

Commit

Permalink
abort storing transcript if previous version is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Apr 26, 2024
1 parent dc06626 commit 1ee476f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions server/cp/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cp
import flask

from typing import Literal, Optional
from flask import current_app as app
Expand Down Expand Up @@ -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"):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ee476f

Please sign in to comment.