learningequality / learningequality/studio

ValueError: Cannot insert a node which has already been saved.

Open
#2,876 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

TAG: tech update / debt
Dominant language
Python
Stars
191
Forks
307
Avg merge
5d 6h
Merged PRs (30d)
10

Description

During shallow copying, sometimes we seem to attempt to insert a node that has already been saved. Possible that this is a result of repeated application of a copy operation?

Sentry Issue: STUDIO-B88

ValueError: Cannot insert a node which has already been saved.
(4 additional frame(s) were not displayed)
...
  File "contentcuration/db/models/manager.py", line 351, in copy_node
    batch_size,
  File "contentcuration/db/models/manager.py", line 385, in _copy
    can_edit_source_channel,
  File "contentcuration/db/models/manager.py", line 531, in _shallow_copy
    self.insert_node(node_copy, target, position=position, save=False)
  File "mptt/managers.py", line 72, in wrapped
    return method(self, *args, **kwargs)
  File "mptt/managers.py", line 522, in insert_node
    raise ValueError(_('Cannot insert a node which has already been saved.'))

Task duplicate_nodes_task[ce3d48ec86a447acb58b4210f0b641c6] raised unexpected: ValueError('Cannot insert a node which has already been saved.',)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Sentry trace and contentcuration/db/models/manager.py at copy_node, _copy, and _shallow_copy, then inspect mptt/managers.py at insert_node. Reproduce or trace duplicate_nodes_task and determine why a saved node reaches insertion; done means the shallow-copy path no longer raises this ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.