Skip to content

Using DestroyElements with delete_children=false does not remove ElementPaths

With this element structure:

image

The contents of ElementPath will be like so:

Element Path
Parent 1
Parent 2
Le Element Parent 1
Le Element Parent 2
Le Child 1 Parent 1, Le Element
Le Child 1 Parent 2, Le Element
Le Child 2 Parent 1, Le Element
Le Child 2 Parent 2, Le Element
Le Grandchild Parent 1, Le Element, Le Child 2
Le Grandchild Parent 2, Le Element, Le Child 2

Let's say you now want to remove all the elements named Le Element on the corpus, but without removing the children (not possible in the frontend, but possible in the API):

cli.request('DestroyElements', corpus=CORPUS_ID, name='Le Element', delete_children=False)

Once the RQ task is complete, the element, its transcriptions, its classifications, its transcription entities, etc. will be properly deleted. But ElementPath now looks like this:

Element Path
Parent 1
Parent 2
Le Child 1 Parent 1, Le Element
Le Child 1 Parent 2, Le Element
Le Child 2 Parent 1, Le Element
Le Child 2 Parent 2, Le Element
Le Grandchild Parent 1, Le Element, Le Child 2
Le Grandchild Parent 2, Le Element, Le Child 2

When we would normally expect this:

Element Path
Parent 1
Parent 2
Child 1
Child 2
Le Grandchild Le Child 2

There still are references to Le Element in the paths, and this causes null values to appear in ListElementNeighbors:

>>> cli.request('ListElementNeighbors', id=LE_CHILD_1)
{'count': 2,
 'number': 1,
 'next': None,
 'previous': None,
 'results': [
  {'position': 0,
   'element': {'id': LE_CHILD_1,
    'type': 'element',
    'name': 'Le Child 1'},
   'parents': [
    None,  # oh no
    {'id': PARENT_1,
    'type': 'element',
    'name': 'Parent 1'}
   ]},
  {'position': 0,
   'element': {'id': LE_CHILD_1,
    'type': 'element',
    'name': 'Le Child 1'},
   'parents': [
    None,  # oh no
    {'id': PARENT_2,
    'type': 'element',
    'name': 'Parent 2'}
   ]}
 ]}

Said null values then cause TypeErrors in the frontend: ARKINDEX-FRONTEND-AG0

Fixing this using SQL queries might be a first and not too difficult step towards someday using raw SQL for add_parent and remove_child.

Edited by Erwan Rouchet