From 7dd3f9adbe3fd70673821d17c997f8c63ad8b691 Mon Sep 17 00:00:00 2001 From: hblankenship Date: Fri, 11 Oct 2024 12:27:41 -0500 Subject: [PATCH] get or create environment --- dojo/api_v2/serializers.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dojo/api_v2/serializers.py b/dojo/api_v2/serializers.py index 471dfc019b5..32c8b2414f7 100644 --- a/dojo/api_v2/serializers.py +++ b/dojo/api_v2/serializers.py @@ -2175,9 +2175,12 @@ def set_context( context = dict(data) # update some vars context["scan"] = data.pop("file", None) - context["environment"] = Development_Environment.objects.get( + # The assumption below is that a Development environment will be gotten or created, whether of the one provided or the Development environment + # because the Development environment always exists... + # If this fails, there are bigger problems. + context["environment"] = Development_Environment.objects.get_or_create( name=data.get("environment", "Development"), - ) + )[0] # Set the active/verified status based upon the overrides if "active" in self.initial_data: context["active"] = data.get("active") @@ -2454,9 +2457,12 @@ def set_context( context = dict(data) # update some vars context["scan"] = data.get("file", None) - context["environment"] = Development_Environment.objects.get( + # The assumption below is that a Development environment will be gotten or created, whether of the one provided or the Development environment + # because the Development environment always exists... + # If this fails, there are bigger problems. + context["environment"] = Development_Environment.objects.get_or_create( name=data.get("environment", "Development"), - ) + )[0] # Set the active/verified status based upon the overrides if "active" in self.initial_data: context["active"] = data.get("active")