Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Make AnnotationCollection.save return its results #39

@schwobr

Description

@schwobr

Hi !

I noticed trying to work with the python client while understanding what happens behind the scenes that an AnnotationCollection doesn't quite behave like a collection of Annotation objects. Specifically, while using Annotation.save() populates the object, most importantly its id, and returns itself, AnnotationCollection.save() does not change the underlying Annotation objects ids and returns a boolean. This is not very handy, as it is impossible to get information from uploaded annotations, for instance their ids that could be later used to upload AnnotationTerm objects.

There are some workarounds, the main one being overwriting some of the source code at runtime but it is not very handy. We could also catch stdout as the response is logged by cytomine. However, I feel like it should be the default behaviour of the API to somehow give us access to annotations ids, that is why I would suggest making one of these changes:

  • The easiest one: make Cytomine.post_collection return the output of self._post and have AnnotationCollection.save return the results instead of a boolean as well. It is however not the most user friendly behaviour.
  • Make Cytomine.post_collection return a list of uploaded ids. This could be more readable and allow for easily checking upload success using the length of the list.
  • Make AnnotationCollection.save populate the underlying annotations and make it return the collection. This would be the most user friendly as it would be consistent with the single element upload behaviour. However it seems that it would also require to change the REST API to make it return a similar response as Annotation.save. It would also potentially be quite slow as the response would be heavy, which I guess is why it does not work like this. We could also have only the ids be populated, which would be enough for most use cases and would not add any weight to the response.

Whatever suits you best, but I think it is important to change the collection API. For anything that does not imply changing the REST API I can help with a PR if you'd like.

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