Skip to content

Commit 7e2e52d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into deploy
2 parents ab485b4 + 579345d commit 7e2e52d

18 files changed

Lines changed: 57 additions & 28 deletions

pygeoapi/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ def get_exception(self, status, headers, format_, code,
604604
else:
605605
content = to_json(exception, self.pretty_print)
606606

607+
if status == HTTPStatus.NO_CONTENT:
608+
LOGGER.error('HTTP 204 detected, suppressing content')
609+
content = ''
610+
607611
return headers, status, content
608612

609613
def get_format_exception(self, request) -> Tuple[dict, int, str]:

pygeoapi/api/processes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050

5151
from pygeoapi import l10n
5252
from pygeoapi.api import evaluate_limit
53-
from pygeoapi.util import (
54-
json_serial, render_j2_template, JobStatus, RequestedProcessExecutionMode,
55-
to_json, DATETIME_FORMAT)
5653
from pygeoapi.process.base import (
5754
JobNotFoundError, JobResultNotFoundError, ProcessorExecuteError
5855
)
5956
from pygeoapi.process.manager.base import get_manager, Subscriber
57+
from pygeoapi.util import (
58+
json_serial, render_j2_template, JobStatus, RequestedProcessExecutionMode,
59+
to_json, DATETIME_FORMAT)
6060

6161
from . import (
6262
APIRequest, API, SYSTEM_LOCALE, F_JSON, FORMAT_TYPES, F_HTML, F_JSONLD,
@@ -520,6 +520,14 @@ def execute_process(api: API, request: APIRequest,
520520
else:
521521
response2 = response
522522

523+
if execution_mode == RequestedProcessExecutionMode.respond_async:
524+
LOGGER.debug('Asynchronous mode detected, returning statusInfo')
525+
response2 = {
526+
'id': job_id,
527+
'type': 'process',
528+
'status': status.value
529+
}
530+
523531
return headers, http_status, response2
524532

525533

pygeoapi/django_/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@
175175
# Defaults to True in Django
176176
# https://docs.djangoproject.com/en/3.2/ref/settings/#append-slash
177177
APPEND_SLASH = not API_RULES.strict_slashes
178+
179+
# CORS: optionally enable from config.
180+
if PYGEOAPI_CONFIG['server'].get('cors', False):
181+
INSTALLED_APPS.append('corsheaders')
182+
MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
183+
184+
CORS_ORIGIN_ALLOW_ALL = True

pygeoapi/provider/csv_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _load(self, offset=0, limit=10, resulttype='results',
159159
coordinates = None
160160

161161
feature = {'type': 'Feature'}
162-
feature['id'] = row.pop(self.id_field)
162+
feature['id'] = row[self.id_field]
163163
if not skip_geometry:
164164
feature['geometry'] = {
165165
'type': 'Point',

pygeoapi/provider/oracle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def _response_feature(self, row_data):
10701070
for (key, value) in row_data.items()
10711071
if key != "GEOMETRY"
10721072
}
1073-
feature["id"] = feature["properties"].pop(self.id_field)
1073+
feature["id"] = feature["properties"][self.id_field]
10741074

10751075
return feature
10761076
else:

pygeoapi/provider/sensorthings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def _make_feature(self, feature, select_properties=[], skip_geometry=False,
305305
306306
:returns: dict of GeoJSON Feature
307307
"""
308-
_ = feature.pop(self.id_field)
308+
_ = feature[self.id_field]
309309
id = f"'{_}'" if isinstance(_, str) else str(_)
310310
f = {
311311
'type': 'Feature', 'id': id, 'properties': {}, 'geometry': None

pygeoapi/provider/socrata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def query(self, offset=0, limit=10, resulttype='results',
138138
params['limit'] = limit
139139

140140
def make_feature(f):
141-
f['id'] = f['properties'].pop(self.id_field)
141+
f['id'] = f['properties'][self.id_field]
142142
if skip_geometry:
143143
f['geometry'] = None
144144
return f
@@ -178,7 +178,7 @@ def get(self, identifier, **kwargs):
178178
LOGGER.debug('Sending query')
179179
fc = self.client.get(self.resource_id, **params)
180180
f = fc.get('features').pop()
181-
f['id'] = f['properties'].pop(self.id_field)
181+
f['id'] = f['properties'][self.id_field]
182182
return f
183183

184184
def _make_fields(self, select_properties=[]):

pygeoapi/provider/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __response_feature(self, row_data, skip_geometry=False):
162162
LOGGER.warning('Missing geometry')
163163

164164
feature['properties'] = rd
165-
feature['id'] = feature['properties'].pop(self.id_field)
165+
feature['id'] = feature['properties'][self.id_field]
166166

167167
return feature
168168
else:

pygeoapi/starlette_app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
""" Starlette module providing the route paths to the api"""
3434

3535
import asyncio
36+
from http import HTTPStatus
3637
import os
3738
from typing import Callable, Union
3839
from pathlib import Path
@@ -133,9 +134,10 @@ async def execute_from_starlette(api_function, request: Request, *args,
133134
headers, status, content = await loop.run_in_executor(
134135
None, call_api_threadsafe, loop, api_function,
135136
actual_api, api_request, *args)
136-
# NOTE: that gzip currently doesn't work in starlette
137-
# https://github.com/geopython/pygeoapi/issues/1591
138-
content = apply_gzip(headers, content)
137+
# 204 responses must have an empty body, but gzip
138+
# encoding would add gzip metadata, thus we skip
139+
if status != HTTPStatus.NO_CONTENT:
140+
content = apply_gzip(headers, content)
139141

140142
response = _to_response(headers, status, content)
141143

requirements-django.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Django
2+
django-cors-headers
23
pydantic

0 commit comments

Comments
 (0)