diff --git a/api/main/models.py b/api/main/models.py index 215ac02b4..52badd0ea 100644 --- a/api/main/models.py +++ b/api/main/models.py @@ -2017,7 +2017,7 @@ def calc_segments(sender, **kwargs): ) # Bring up related media to association - instance.media.add(sortedLocalizations.all().values_list("media", flat=True)) + instance.media.add(*sortedLocalizations.all().values_list("media", flat=True)) segmentList = [] current = [None, None] last = None diff --git a/api/main/rest/state.py b/api/main/rest/state.py index dee762ab4..0311aefaa 100644 --- a/api/main/rest/state.py +++ b/api/main/rest/state.py @@ -467,6 +467,7 @@ def patch_qs(self, params, qs): raise Http404 obj = qs[0] model_dict = obj.model_dict + association_type = obj.type.association # If this is a really old object, it may not have an elemental_id # but we need to add it for trigger support @@ -493,18 +494,38 @@ def patch_qs(self, params, qs): if "media_ids" in params: media_elements = Media.objects.filter(pk__in=params["media_ids"]) obj.media.set(media_elements) + if association_type != "Media": + logger.warning( + f"Media set on state {obj.id} of type {association_type}." + "This is not a Media type state." + ) if "localization_ids" in params: localizations = Localization.objects.filter(pk__in=params["localization_ids"]) obj.localizations.set(localizations) + if association_type != "Localization": + logger.warning( + f"Media set on state {obj.id} of type {association_type}." + "This is not a Media type state." + ) if "localization_ids_add" in params: localizations = Localization.objects.filter(pk__in=params["localization_ids_add"]) obj.localizations.add(*list(localizations)) + if association_type != "Localization": + logger.warning( + f"Media set on state {obj.id} of type {association_type}." + "This is not a Media type state." + ) if "localization_ids_remove" in params: localizations = Localization.objects.filter(pk__in=params["localization_ids_remove"]) obj.localizations.remove(*list(localizations)) + if association_type != "Localization": + logger.warning( + f"Media set on state {obj.id} of type {association_type}." + "This is not a Media type state." + ) if params.get("user_elemental_id", None): params["in_place"] = 1