Skip to content

API doesn't allow adding an Item to a Collection if geometry field is missing or null #169

Open
@mcucchi9

Description

@mcucchi9

Description

When trying to submit a POST /collections/{collection_id}/items request the following behaviors occur:

  • if the geometry field is missing, I get a 400 response associated to a RequestValidationError stating that the geometry field is required;
  • if the geometry field is null, I get a 424 response associated to a DatabaseError, which appears to be caused by the fact that the geometry column in the postgres datbase is not nullable;

Expected behavior

The STAC Item specification for the geometry field states that

If a geometry is provided, the value must be a Geometry Object according to RFC 7946, section 3.1 with the exception that the type GeometryCollection is not allowed in STAC. If no geometry is provided, the value must be null according to RFC 7946, section 3.2.

I would thus expect it to be possible to at least create an Item with the geometry property set to null.

How to replicate

After cloning the repository, in its root directory launch

docker compose -f docker-compose.yml up

Then

curl -X 'POST' \
  'http://0.0.0.0:8082/collections/joplin/items' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "f2cca2a3-288b-4518-8a3e-a4492bb60b08",
    "type": "Feature",
    "collection": "joplin",
    "links": [],
    "properties": {
        "datetime": "2000-02-02T00:00:00Z"
    },
    "assets": {},
    "stac_extensions": [],
    "stac_version": "1.0.0"
}'

which results in

{"code":"RequestValidationError","description":"[{'type': 'missing', 'loc': ('body', 'Item', 'geometry'), 'msg': 'Field required', 'input': {'id': 'f2cca2a3-288b-4518-8a3e-a4492bb60b08', 'type': 'Feature', 'collection': 'joplin', 'links': [], 'properties': {'datetime': '2000-02-02T00:00:00Z'}, 'assets': {}, 'stac_extensions': [], 'stac_version': '1.0.0'}}, {'type': 'literal_error', 'loc': ('body', 'ItemCollection', 'type'), 'msg': \"Input should be 'FeatureCollection'\", 'input': 'Feature', 'ctx': {'expected': \"'FeatureCollection'\"}}, {'type': 'missing', 'loc': ('body', 'ItemCollection', 'features'), 'msg': 'Field required', 'input': {'id': 'f2cca2a3-288b-4518-8a3e-a4492bb60b08', 'type': 'Feature', 'collection': 'joplin', 'links': [], 'properties': {'datetime': '2000-02-02T00:00:00Z'}, 'assets': {}, 'stac_extensions': [], 'stac_version': '1.0.0'}}]"}

Also, try

curl -X 'POST' \
  'http://0.0.0.0:8082/collections/joplin/items' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "f2cca2a3-288b-4518-8a3e-a4492bb60b08",
    "type": "Feature",
    "geometry": null,
    "collection": "joplin",
    "links": [],
    "properties": {
        "datetime": "2000-02-02T00:00:00Z"
    },
    "assets": {},
    "stac_extensions": [],
    "stac_version": "1.0.0"
}'

which results in

{
  "code": "DatabaseError",
  "description": ""
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions