From d7b112f62b9dddfad1e7f73ec18175df015929ae Mon Sep 17 00:00:00 2001 From: totycro Date: Sat, 1 Jul 2023 15:06:36 +0200 Subject: [PATCH] Avoid internal server error when no format requested in get_collection_item (#1274) Previously, request.format was assumed to always be defined when generating `prev` and `next` links. This commit changes this by using json as default format. This supports the use case of curl nicely, but we could also choose e.g. html. This branch is not yet tested because I didn't manage to find/produce test data for single items which have next/previous links. Fixes https://github.com/geopython/pygeoapi/issues/1272 --- pygeoapi/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 1de03d5..bbb12e7 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -2363,17 +2363,20 @@ class API: 'href': f'{self.get_collections_url()}/{dataset}' }]) + link_request_format = ( + request.format if request.format is not None else F_JSON + ) if 'prev' in content: content['links'].append({ 'rel': 'prev', - 'type': FORMAT_TYPES[request.format], - 'href': f"{self.get_collections_url()}/{dataset}/items/{content['prev']}?f={request.format}" # noqa + 'type': FORMAT_TYPES[link_request_format], + 'href': f"{self.get_collections_url()}/{dataset}/items/{content['prev']}?f={link_request_format}" # noqa }) if 'next' in content: content['links'].append({ 'rel': 'next', - 'type': FORMAT_TYPES[request.format], - 'href': f"{self.get_collections_url()}/{dataset}/items/{content['next']}?f={request.format}" # noqa + 'type': FORMAT_TYPES[link_request_format], + 'href': f"{self.get_collections_url()}/{dataset}/items/{content['next']}?f={link_request_format}" # noqa }) # Set response language to requested provider locale