Skip to content

execute_process is not able to respond async if job output media type is different from application/json #2311

@ricardogsilva

Description

@ricardogsilva

It is currently not possible to have a process that operates in async mode and generates an output with a media type that is not JSON.

As per this section of the execute_process API handler:

if mime_type == 'application/json':
if requested_response == 'document':
pretty_print_ = api.pretty_print
else: # raw
pretty_print_ = False
response2 = to_json(response, pretty_print_)
else:
response2 = response
if (headers.get('Preference-Applied', '') == RequestedProcessExecutionMode.respond_async.value): # noqa
LOGGER.debug('Asynchronous mode detected, returning statusInfo')
response2 = {
'jobID': job_id,
'type': 'process',
'status': status.value
}
response2 = to_json(response2, pretty_print_)

It can be observed that:

  • When the if mime_type == "application/json" condition is False (line 530), the pretty_print_ variable is never created.
  • Regardless, this variable is accessed later (line 540) if the processor is executing in async mode. This causes this error:
  File "/home/ricardo/dev/pygeoapi/pygeoapi/api/processes.py", line 540, in execute_process
    response2 = to_json(response2, pretty_print_)
                                   ^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'pretty_print_' where it is not associated with a value

@tomkralidis this seems to be a regression introduced in 0b53d49 like #2304

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions