Skip to content

Deleting a corpus fails if the corpus has a top_level_type

  1. Create a corpus
  2. Set any of its types as its top_level_type in the Django admin
  3. Destroy that corpus using DestroyCorpus
  4. Watch as the RQ task fails when deleting ElementTypes.
django.db.utils.IntegrityError: update or delete on table "documents_elementtype" violates foreign key constraint "documents_corpus_top_level_type_id_4bda20f5_fk_documents" on table "documents_corpus"
DETAIL:  Key (id)=(fa36cdc6-aba9-4e52-8aab-b5b4cf539247) is still referenced from table "documents_corpus".

The FK already has on_delete=models.SET_NULL, but it is ignored in corpus deletions as we use _raw_delete.