learningequality / studio

Content curation tools for Kolibri
https://studio.learningequality.org/
MIT License
112 stars 160 forks source link

Inconsistent state of completion criteria in contentnode due to backend validation errors #4665

Open ozer550 opened 1 month ago

ozer550 commented 1 month ago

Observed behavior

When a user attempts to update the completion criteria of a ContentNode, the system fails to revert to the last valid state if a backend validation error occurs. This results in an unexpected state of completion criteria, which does not reflect the last correct configuration.

Expected behavior

Frontend should have the last correct state of completion criteria (we would want to revert the optimistic changes) in such a way that the user knows that other changes have overridden theirs.

User-facing consequences

Inconsistent/Incorrect state of completion criteria for a Contentnode while collaborating.

Errors and logs

[2024-08-20 08:05:32,634: ERROR/ForkPoolWorker-1] [ErrorDetail(string='["Completion criteria doesn\'t conform to schema", "object doesn\'t satisfy \'anyOf\' conditions"]', code=None)]
Traceback (most recent call last):
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/contentnode.py", line 414, in _check_completion_criteria
    completion_criteria_validator.validate(completion_criteria, kind)
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/constants/completion_criteria.py", line 97, in validate
    raise e
django.core.exceptions.ValidationError: ["Completion criteria doesn't conform to schema", "object doesn't satisfy 'anyOf' conditions"]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/base.py", line 864, in update_from_changes
    self.perform_bulk_update(serializer)
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/base.py", line 851, in perform_bulk_update
    serializer.save()
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/base.py", line 364, in save
    instance = super(BulkListSerializer, self).save(**kwargs)
  File "/home/ozer/.pyenv/versions/3.10.13/envs/studio-py3.10/lib/python3.10/site-packages/rest_framework/serializers.py", line 753, in save
    self.instance = self.update(self.instance, validated_data)
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/contentnode.py", line 250, in update
    all_objects = super(ContentNodeListSerializer, self).update(
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/base.py", line 311, in update
    instance = self.child.update(obj, obj_validated_data)
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/contentnode.py", line 445, in update
    self._check_completion_criteria(validated_data.get("kind", instance.kind_id), validated_data.get("complete", instance.complete), validated_data)
  File "/home/ozer/workspace/LE/studio/contentcuration/contentcuration/viewsets/contentnode.py", line 418, in _check_completion_criteria
    raise ValidationError(e)
rest_framework.exceptions.ValidationError: [ErrorDetail(string='["Completion criteria doesn\'t conform to schema", "object doesn\'t satisfy \'anyOf\' conditions"]', code=None)]

Additional information

follow up #3879

Steps to reproduce the issue

  1. Open studio in two different browsers.
  2. Login with admin user and userC.
  3. Simultaneously open same ContentNode with content kind html5 in both tabs.
  4. First change the completion criteria to aprrox time mode.
  5. In one tab change the model to refrence .
  6. Simultaneously on other tab change the time threshold to valid different value.
shivam-daksh commented 4 days ago

Hey @ozer550, May I look into it?

MisRob commented 3 days ago

Hi @shivam-daksh, thanks for volunteering. I just assigned you another issue. Please ask for an assignment of a reasonable amount of issues - typically we would assign only one or two issues max at once. We're happy to assign you more 'help wanted' later on.