Skip to content

Commit

Permalink
[bugfix] Fix broken run_detector for non-change detectors
Browse files Browse the repository at this point in the history
The HTTP API for running detectors accept only a "raster_id" POST field
for non-change detectors, but our Python library was sending also a
"secondary_raster_id" with a None value, resulting in a server error.

This fixes it.
  • Loading branch information
ao-picterra authored and julienr committed Jul 10, 2024
1 parent 26b0042 commit 0da41e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/picterra/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,12 @@ def run_detector(
operation_id: The id of the operation. You typically want to pass this
to `download_result_to_feature_collection`
"""
body = {"raster_id": raster_id}
if secondary_raster_id is not None:
body["secondary_raster_id"] = secondary_raster_id
resp = self.sess.post(
self._api_url("detectors/%s/run/" % detector_id),
json={"raster_id": raster_id, "secondary_raster_id": secondary_raster_id},
json=body,
)
if not resp.ok:
raise APIError(resp.text)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ def add_mock_remote_import_responses(upload_id, post_body):


def add_mock_detector_run_responses(detector_id, raster_id, secondary_raster_id=None):
data = {"raster_id": raster_id}
if secondary_raster_id:
data["secondary_raster_id"] = secondary_raster_id
_add_api_response(
"detectors/%s/run/" % detector_id, responses.POST, OP_RESP,
match=responses.matchers.json_params_matcher({
"raster_id": raster_id,
"secondary_raster_id": secondary_raster_id,
}),
match=responses.matchers.json_params_matcher(data),
)
# First status check
data = {"status": "running"}
Expand Down

0 comments on commit 0da41e0

Please sign in to comment.