LibCrowds/libcrowds

Tagging sometimes throws an error

mialondon opened this issue · 4 comments

As described in https://community.libcrowds.com/d/44-your-requests-for-help-questions-about-the-project/11

Attached should be the error message. To reproduce:

  • type 'elephant' into the tag field
  • scroll down to one of the entries for elephant that appear in the drop-down tag list and press Enter
  • the tag field now shows two elephant tags (highlighted in green)
  • delete the first of the two tags (if you delete the second tag the error does not appear, but a duplicate tag is still created)

Possibly related to #829

If you tag an image, the tag is apparently submitted but then you get a 'Forbidden' 'Request failed with status code 403' error message when you try to submit the task.

e.g. on https://www.libcrowds.com/collection/playbills/projects/178/iiif-annotation

Definition of success: the tagging function pulls up existing tags quickly so that people add existing tags to images rather than creating a separate new version of the same tag.

I've pushed a 2020-fixes branch that contains a fix for this bug.

Issues:
In the auto-complete we had two issues with duplicated tags:

  1. the tags were duplicated in the suggestion drop down when the user was searching for some words like 'elephant', 'ramo', Shakespeare'
  2. the tags were duplicated in the tagging text box when the user was selecting suggestions (e.g. click on 'elephant' in the drop down => two 'elephant' appear to be selected)
  3. it is possible for the user to remove tags applied by other users to other images
  4. removing the first tag can throw an error

Causes
The duplication issues were not caused by the performance problem.

  1. was caused by the by the auto-complete fetching annotations from Explicates Search API endpoint. An annotation is one or more tags applied to a specific image. So if the same tag was applied to multiple images it would appear multiple times in the drop down;
  2. The Libcrowds custom code creates a new Annotation record and adds its tag to the list of selected tag. That's correct behaviour and it corresponds to the second selected 'elephant'. However the auto-complete widget first selects the item the user has clicked one. That is an existing annotation already applied to another image (see cause 1) above). That explains the first 'elephant', it should never have been selected because it doesn't belong to the current image.
  3. That explains why, when the user clicks the first tag they are actually removing a pre-existing annotation that belongs to another image! This, in turn, might explain why there are many annotations marked as deleted in the database.
  4. As a side effect of 3), it was possible to select an already deleted tag (as the auto-complete widget caches the suggestions). If the user tries to remove it, an error will be thrown because it is already marked as deleted in the Explicates database.

Fixes

  • Issues 2), 3), 4) were fixed by making sure the tag the user clicks in the dropdown is never selected, only a new annotation is created for the current image on click
  • Issue 1) was fixed by creating a new Explicates API endpoint: /tags/ and making the auto-complete use that instead of /search/ endpoint. /search/ returns annotations, /tags/ returns unique tags

Deployment

  • Please checkout the 2020-fixes branch of both Explicates and Libcrowds code base. For Explicates, see the KDL fork.
  • Please test thoroughly and tell us if resolution is accepted before deploying live.
  • Highly recommended to create a backup of the Explicates database before you deploy.

Other fixed bugs

  • when user doesn't type anything in the box, the dropdown was showing the last fetched results, including tags which were already removed => the drop-down now remains empty when the user doesn't type anything;
  • it used to be possible to create a empty tag, just by pressing the space bar in the input box, an error message will now appear instead;

@mialondon @harjmos Please see resolution comment, let me know if you have any question/problem.