From 7f047348b52a9646f8bae61a8d21fe5af1fcfadf Mon Sep 17 00:00:00 2001 From: Mathieu Tachon <92298764+MTachon@users.noreply.github.com> Date: Fri, 10 Feb 2023 21:06:23 +0100 Subject: [PATCH] fix(OGRProvider_init): make the 'id_field' attribute mandatory in provider config (#1135) As for the 'layer' attribute, the 'id_field' should be specified in the configuration file for the OGRProvider. The 'get' method of a OGRProvider instance (e.g. when requesting a single feature) needs the feature ID when setting an attribute filter on the layer. If the 'id_field' attribute is omitted in the configuration file, the error thrown is more explicit. --- pygeoapi/provider/ogr.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pygeoapi/provider/ogr.py b/pygeoapi/provider/ogr.py index f2375cf..0745625 100644 --- a/pygeoapi/provider/ogr.py +++ b/pygeoapi/provider/ogr.py @@ -171,6 +171,13 @@ class OGRProvider(BaseProvider): self._load_source_helper(self.data_def['source_type']) + # ID field is required + self.id_field = provider_def.get('id_field') + if not self.id_field: + msg = 'Need explicit \'id_field\' attr in provider config' + LOGGER.error(msg) + raise Exception(msg) + # Layer name is required self.layer_name = provider_def.get('layer') if not self.layer_name: