Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactions endpoint responses include incorrect links #423

Closed
duckontheweb opened this issue Jul 18, 2022 · 0 comments · Fixed by #424
Closed

Transactions endpoint responses include incorrect links #423

duckontheweb opened this issue Jul 18, 2022 · 0 comments · Fixed by #424

Comments

@duckontheweb
Copy link
Contributor

When using POST /collections to add a new Collection, the self and root links in the response are the original links from the submitted Collection instead of the links for the newly created Collection in the API.

Observed Response
As an example, add the following self link to the example joplin Collection:

{
    "rel": "self",
    "href": "/some/path/to/collection.json"
}

The POST /collections response includes that same self link unchanged:

$ curl -X POST -H "Content-Type: application/json" -d "@tests/data/transactions_api/collection.json" -s http://localhost:8080/collections | jq ".links[] | select(.rel == \"self\")"
{
  "rel": "self",
  "href": "/some/path/to/collection.json"
}

The same issue exists with PUT /collections, POST /collections/{collection_id}/items, and PUT /collections/{collection_id}/items.

Expected Response
I expected this to instead return the new self link:

$  curl -X POST -H "Content-Type: application/json" -d "@tests/data/transactions_api/collection.json" -s http://localhost:8080/collections | jq ".links[] | select(.rel == \"self\")"
{
  "rel": "self",
  "type": "application/json",
  "href": "http://localhost:8080/collections/joplin"
}

Possible Solution

This can be easily fixed by adding the CollectionLinks logic to the AsyncBaseTransactionsClient.create_collection handler (and the equivalent handlers for the other endpoints):

async def create_collection(
    self, collection: stac_types.Collection, **kwargs
) -> Optional[Union[stac_types.Collection, Response]]:
    """Create collection."""
    request = kwargs["request"]
    pool = request.app.state.writepool
    await dbfunc(pool, "create_collection", collection)
    collection["links"] = await CollectionLinks(
        collection_id=collection["id"], request=request
    ).get_links(extra_links=collection.get("links"))

    return stac_types.Collection(**collection)

Just a note that this would be really helpful in implementing a solution for stac-utils/pystac-client#241 because we could create a CollectionClient directly from the POST or PUT response rather than having to fetch the Collection again in order to get the correct links.

I can work on a PR for this in the pgstac backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant