Skip to content

UpdateElement does not check image dimensions when generating a polygon

The UpdateElement and PartialUpdateElement API endpoints allow adding a zone to an element by sending the image ID and, optionally, a polygon. When the polygon is not set, the API will use a polygon filling the whole image. CreateElement has the same behavior; however, while CreateElement checks for valid image dimensions before setting a polygon, UpdateElement does not. If an image is Unchecked, it will have a width of 0 and a height of 0, causing the update to create a 0 pixel-wide and 0 pixel-high polygon.

Currently, this situation causes no error (but an element in this state could break the frontend or any worker). With PostGIS (#163 (closed)), this causes a ValueError in the polygon validation code: At least 4 distinct points are required.. https://sentry.io/organizations/teklia/issues/1884002205/

>>> element = cli.request('CreateElement', 'corpus_id': '...', 'type': 'page', 'name': 'something'})
>>> cli.request('PartialUpdateElement', id=element['id'], body={'image': '...'})  # ID of any 0px×0px image
# Without PostGIS
{'id': '...',
 'type': 'page',
 'name': 'something',
 'corpus': {...},
 'zone': {
   'id': '...',
   'image': {...},
   'polygon': [[0, 0], [0, 0], [0, 0]]
 }
}
# With PostGIS
ErrorResponse('500 Internal Server Error', status_code=500, ...)
Edited by Erwan Rouchet