Skip to content

Commit d32a7da

Browse files
Merge pull request #1042 from adamtheturtle/deleted-query
Raise exception when a deleted target is matched
2 parents 0d454a1 + ceae924 commit d32a7da

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/vws/exceptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
from requests import Response
66

77

8+
class MatchDeleted(Exception):
9+
"""
10+
Exception raised when a query is made with an image which matches a target
11+
which has recently been deleted.
12+
"""
13+
14+
def __init__(self, response: Response) -> None:
15+
"""
16+
Args:
17+
response: The response to a request to Vuforia.
18+
"""
19+
super().__init__()
20+
self._response = response
21+
22+
@property
23+
def response(self) -> Response:
24+
"""
25+
The response returned by Vuforia which included this error.
26+
"""
27+
return self._response
28+
29+
830
class MaxNumResultsOutOfRange(Exception):
931
"""
1032
Exception raised when the ``max_num_results`` given to the Cloud

src/vws/query.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from ._authorization import authorization_header, rfc_1123_date
1313
from ._result_codes import raise_for_result_code
14-
from .exceptions import MaxNumResultsOutOfRange
14+
from .exceptions import MatchDeleted, MaxNumResultsOutOfRange
1515
from .include_target_data import CloudRecoIncludeTargetData
1616

1717

@@ -105,6 +105,9 @@ def query(
105105
if 'Integer out of range' in response.text:
106106
raise MaxNumResultsOutOfRange(response=response)
107107

108+
if 'No content to map due to end-of-input' in response.text:
109+
raise MatchDeleted(response=response)
110+
108111
raise_for_result_code(
109112
response=response,
110113
expected_result_code='Success',

tests/test_exceptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
BadImage,
1919
Fail,
2020
ImageTooLarge,
21+
MatchDeleted,
2122
MetadataTooLarge,
2223
ProjectInactive,
2324
TargetNameExist,
@@ -270,3 +271,24 @@ def test_target_status_not_success(
270271
vws_client.update_target(target_id=target_id)
271272

272273
assert exc.value.response.status_code == codes.FORBIDDEN
274+
275+
276+
def test_match_deleted(
277+
vws_client: VWS,
278+
cloud_reco_client: CloudRecoService,
279+
high_quality_image: io.BytesIO,
280+
) -> None:
281+
"""
282+
A ``MatchDeleted`` exception is raised when a deleted target is matched.
283+
"""
284+
target_id = vws_client.add_target(
285+
name='x',
286+
width=1,
287+
image=high_quality_image,
288+
)
289+
vws_client.wait_for_target_processed(target_id=target_id)
290+
vws_client.delete_target(target_id=target_id)
291+
with pytest.raises(MatchDeleted) as exc:
292+
cloud_reco_client.query(image=high_quality_image)
293+
294+
assert exc.value.response.status_code == codes.INTERNAL_SERVER_ERROR

0 commit comments

Comments
 (0)