From 05422efb2b9cb42bc7957d8a022b1d74142e8dd6 Mon Sep 17 00:00:00 2001 From: Jo Kristian Bergum Date: Wed, 8 Nov 2023 19:00:46 +0100 Subject: [PATCH 1/2] Get should not raise on 404 --- vespa/application.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vespa/application.py b/vespa/application.py index 51529df4..58ca49a2 100644 --- a/vespa/application.py +++ b/vespa/application.py @@ -2,6 +2,7 @@ import sys import ssl +from xmlrpc.client import Boolean import aiohttp import asyncio import requests @@ -35,13 +36,14 @@ VESPA_CLOUD_SECRET_TOKEN: str = "VESPA_CLOUD_SECRET_TOKEN" -def raise_for_status(response: Response) -> None: +def raise_for_status(response: Response, ignore_not_found:bool=False) -> None: """ Raises an appropriate error if necessary. If the response contains an error message, VespaError is raised along with HTTPError to provide more details. :param response: Response object from Vespa API. + :param ignore_not_found: If True, ignore 404 status code. :raises HTTPError: If status_code is between 400 and 599. :raises VespaError: If the response JSON contains an error message. """ @@ -50,6 +52,8 @@ def raise_for_status(response: Response) -> None: except HTTPError as http_error: try: response_json = response.json() + if response.status_code == 404 and ignore_not_found: + return except JSONDecodeError: raise http_error errors = response_json.get("root", {}).get("errors", []) @@ -782,7 +786,7 @@ def get_data( self.app.end_point, namespace, schema, str(data_id) ) response = self.http_session.get(end_point, params=kwargs) - raise_for_status(response) # This is questionable, since it will throw on 404 as well. + raise_for_status(response,ignore_not_found=True) return VespaResponse( json=response.json(), status_code=response.status_code, From 103e0ac14b8cad2c1abeeb08a87a4bb1c6a2b504 Mon Sep 17 00:00:00 2001 From: Jo Kristian Bergum Date: Wed, 8 Nov 2023 19:01:03 +0100 Subject: [PATCH 2/2] Update tests --- vespa/test_integration_vespa_cloud.py | 3 +++ vespa/test_integration_vespa_cloud_token.py | 6 +++++- vespa/test_integration_vespa_cloud_vector_search.py | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vespa/test_integration_vespa_cloud.py b/vespa/test_integration_vespa_cloud.py index 84f39f35..ffb2a944 100644 --- a/vespa/test_integration_vespa_cloud.py +++ b/vespa/test_integration_vespa_cloud.py @@ -63,12 +63,15 @@ def test_key_cert_arguments(self): }, self.app.get_data(data_id="1").json, ) + self.assertEqual(self.app.get_data(data_id="1").is_successfull(), False) + def tearDown(self) -> None: self.app.delete_all_docs( content_cluster_name="msmarco_content", schema="msmarco" ) shutil.rmtree(self.disk_folder, ignore_errors=True) + #self.vespa_cloud.delete() class TestMsmarcoApplication(TestApplicationCommon): diff --git a/vespa/test_integration_vespa_cloud_token.py b/vespa/test_integration_vespa_cloud_token.py index be4a0ada..fb7d29bd 100644 --- a/vespa/test_integration_vespa_cloud_token.py +++ b/vespa/test_integration_vespa_cloud_token.py @@ -4,6 +4,8 @@ import asyncio import shutil import unittest +import pytest +from requests import HTTPError from vespa.application import Vespa from vespa.package import AuthClient, Parameter from vespa.deployment import VespaCloud @@ -48,7 +50,6 @@ def test_right_endpoint_used_with_token(self): # The token is used to access the application status endpoint. print("Endpoint used " + self.app.url) self.app.wait_for_application_up(max_wait=APP_INIT_TIMEOUT) - self.assertEqual(200, self.app.get_application_status().status_code) self.assertDictEqual( { "pathId": "/document/v1/msmarco/msmarco/docid/1", @@ -56,12 +57,15 @@ def test_right_endpoint_used_with_token(self): }, self.app.get_data(data_id="1").json, ) + self.assertEqual(self.app.get_data(data_id="1").is_successfull(), False) + def tearDown(self) -> None: self.app.delete_all_docs( content_cluster_name="msmarco_content", schema="msmarco" ) shutil.rmtree(self.disk_folder, ignore_errors=True) + #self.vespa_cloud.delete() class TestMsmarcoApplicationWithTokenAuth(TestApplicationCommon): diff --git a/vespa/test_integration_vespa_cloud_vector_search.py b/vespa/test_integration_vespa_cloud_vector_search.py index cbc98602..1209b51d 100644 --- a/vespa/test_integration_vespa_cloud_vector_search.py +++ b/vespa/test_integration_vespa_cloud_vector_search.py @@ -2,8 +2,6 @@ import os import shutil -import asyncio -from typing import Iterable import unittest from vespa.application import Vespa, ApplicationPackage from vespa.package import Schema, Document, Field, HNSW, RankProfile @@ -163,5 +161,6 @@ def tearDown(self) -> None: self.assertEqual(len(response.hits), 0) print(response.get_json()) shutil.rmtree(self.disk_folder, ignore_errors=True) + #self.vespa_cloud.delete()