From d3e7ebea65a07efc2ce518133d0604492411df84 Mon Sep 17 00:00:00 2001 From: Minu Mathew Date: Mon, 22 Jan 2024 14:25:02 -0600 Subject: [PATCH] check for None response --- ai_ta_backend/agents/utils.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ai_ta_backend/agents/utils.py b/ai_ta_backend/agents/utils.py index 44c7f8ff..08209ba8 100644 --- a/ai_ta_backend/agents/utils.py +++ b/ai_ta_backend/agents/utils.py @@ -251,7 +251,10 @@ def fetch_field_from_db(self, field: str): """ response = self.supabase_client.table("docker_images").select(field). \ eq("image_name", self.image_name).execute() - return response.data[0][field] + if response.data is not None: + return response.data[0][field] + else: + return None def update_field_in_db(self, field: str, value: Any): """Method to update field in supabase DB. @@ -263,7 +266,10 @@ def update_field_in_db(self, field: str, value: Any): """ response = self.supabase_client.table("docker_images").update({field: value}). \ eq("image_name", self.image_name).execute() - return response + if response.data is not None: + return response + else: + return None def upsert_field_in_db(self, field, value): """Method to upsert field in supabase DB. @@ -273,9 +279,11 @@ def upsert_field_in_db(self, field, value): Returns: APIResponse: Response from Supabase. """ - response = self.supabase_client.table("docker_images").upsert({field: value}). \ - eq("image_name", self.image_name).execute() - return response + response = self.supabase_client.table("docker_images").upsert({"image_name": self.image_name, field: value}).execute() + if response.data is not None: + return response + else: + return None def check_and_insert_image_name(self, image_name): """Check if the image name exists in the Supabase table, if not, insert it and build a Docker image.