stac-utils/stac-fastapi-elasticsearch-opensearch

Are item IDs intended to be unique across all collections?

Closed this issue · 2 comments

Describe the bug
Currently item ID's are required to be unique across all collections. (Not sure if bug or not)

To Reproduce
Steps to reproduce the behavior:

  1. Run instance docker-compose up
  2. Create collection with id collection1
  3. Create collection with id collection2
  4. Create item with id item1 in collection collection1
  5. Create item with id item1 in collection collection2
  6. See error:
{
	"code": "ConflictError",
	"description": "Item item1 in collection collection1 already exists"
}

Expected behavior
Unsure.

Screenshots
image

I think this should not happen, item IDs should only be unique within the collection.
Not sure how you got this error, it seems like it is covered in the database logic:

if not exist_ok and await self.client.exists(
index=index_by_collection_id(item["collection"]),
id=mk_item_id(item["id"], item["collection"]),
):

Or does the Item contain the collection ID? It might be possible to POST an Item where the collection in the HTTP request does not match the collection specified in the Item body.

item = await self.database.prep_create_item(item=item, base_url=base_url)

Or does the Item contain the collection ID

You are right, my mistake...

Although this doesn't seem very logical, the collection id shouldn't be passed in the item body at all in my opinion since we already specify the collection id in the request URL:

POST http://localhost:8080/collections/{collection_id}/items