Skip to content

Commit 0b53d49

Browse files
authored
OAProc: fix gzip compression on async process execution (#2238) (#2240)
* OAProc: fix gzip encoding for async process execution (#2238) * support literals for process execution responses * update tests * fix flake8
1 parent 19cc618 commit 0b53d49

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

pygeoapi/api/processes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ def execute_process(api: API, request: APIRequest,
535535
'type': 'process',
536536
'status': status.value
537537
}
538+
response2 = to_json(response2, pretty_print_)
538539

539540
if api.pubsub_client is not None:
540541
LOGGER.debug('Publishing message')

pygeoapi/process/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def execute(self, data: dict, outputs: Optional[dict] = None
8282
The value of any key may be an object and include the
8383
property `transmissionMode` - defaults to `value`.
8484
:returns: tuple of MIME type and process response
85-
(string or bytes, or dict)
85+
(string, bytes, list or dict)
8686
"""
8787

8888
raise NotImplementedError()

pygeoapi/process/manager/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
277277
current_status = JobStatus.running
278278
jfmt, outputs = p.execute(data_dict, **extra_execute_parameters)
279279

280+
if isinstance(outputs, bytes):
281+
outputs = outputs.decode('utf-8')
282+
280283
if requested_response == RequestedResponse.document.value:
281284
outputs = {
282285
'outputs': [outputs]
@@ -299,6 +302,10 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
299302
mode = 'wb'
300303
data = outputs
301304
encoding = None
305+
elif isinstance(outputs, str):
306+
mode = 'w'
307+
data = outputs
308+
encoding = None
302309
with job_filename.open(mode=mode, encoding=encoding) as fh:
303310
fh.write(data)
304311

tests/api/test_processes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ def test_execute_process(config, api_):
331331
req = mock_api_request(data=req_body_1, HTTP_Prefer='respond-async')
332332
rsp_headers, code, response = execute_process(api_, req, 'hello-world')
333333

334-
assert 'Location' in rsp_headers
334+
response = json.loads(response)
335335
assert code == HTTPStatus.CREATED
336+
337+
assert 'Location' in rsp_headers
336338
assert isinstance(response, dict)
337339
assert 'jobID' in response
338340
assert 'type' in response

0 commit comments

Comments
 (0)