Skip to content

Fix Harvester lookup failure caused by trailing ? during the remote resource upload through the API #14111

@Gpetrak

Description

@Gpetrak

For the remote resource upload through the API, the following rerquest can be used:

curl --location 'http://<domain>/api/v2/uploads/upload' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
    "url": "https://development.demo.geonode.org/geoserver/wms",
    "title": "Remote WMS Test",
    "type": "wms",
    "identifier": "geonode:test_layer",
    "parse_remote_metadata": false,
    "action": "upload"
}'

During the upload process, the workflow checks if the external service which is defined through the URL (https://development.demo.geonode.org/geoserver/wms) is a registered service / harvester. If this service is registered, the uploaded resource is linked with the corresponding harvestable resource of this service / harvester.
The corresponding logic is appplied in the create_harvestable_resource method.

But because of this line of the RemoteWMSResourceHandler the corresponding URL which is retrieved by the create_harvestable_resource is this one: https://development.demo.geonode.org/geoserver/wms? (notice the trailing ? in the end).
Thus the service / harvester lookup will always return None even if the service is registered: https://github.com/GeoNode/geonode/blob/master/geonode/harvesting/utils.py#L32

Proposed Solution

We can just replace this line:

ows_url = f"{parsed_url}?{cleaned_url.query}"

with this:

ows_url = f"{parsed_url}?{cleaned_url.query}" if cleaned_url.query else parsed_url

In this way, we can handle both cases (with or without an extra query)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions