From 498a2a58afd790986244bfdf542304ccc9c5cef8 Mon Sep 17 00:00:00 2001 From: Brian Tate Date: Tue, 4 Jun 2024 15:18:30 -0400 Subject: [PATCH 1/2] .add() doesn't take a queryset like .set() did. --- api/main/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e0ef133f4f179f5db8e353c17e2271dacf55a2c6 Mon Sep 17 00:00:00 2001 From: Brian Tate Date: Tue, 4 Jun 2024 15:24:09 -0400 Subject: [PATCH 2/2] Add logging for crossing type definitions. --- api/main/rest/state.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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