Skip to content

Commit

Permalink
Fix unability to delete corpora with custom dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Mar 19, 2024
1 parent 63661c3 commit d5d59af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, user, corpus, is_owner=False):
class Column(db.Model):
"""Column."""
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
corpus_id = db.Column(db.Integer, db.ForeignKey("corpus.id"))
corpus_id = db.Column(db.Integer, db.ForeignKey("corpus.id", ondelete="CASCADE"))
heading = db.Column(db.String(32))
hidden = db.Column(db.Boolean, default=False)

Expand Down Expand Up @@ -1367,7 +1367,7 @@ class TYPES(enum.Enum):
class CorpusCustomDictionary(db.Model):

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
corpus = db.Column(db.Integer, db.ForeignKey('corpus.id'), nullable=False)
corpus = db.Column(db.Integer, db.ForeignKey('corpus.id', ondelete="CASCADE"), nullable=False)
label = db.Column(db.String(128), nullable=False)
secondary_label = db.Column(db.String(128))
category = db.Column(db.String(10), nullable=False)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_models/test_word_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ def test_update_batch_context(self):
self.assertEqual(left_context[3], form_list[13]["form"])
self.assertEqual(right_context[0], form_list[15]["form"])
self.assertEqual(right_context[3], form_list[18]["form"])

def test_remove_corpus(self):
self.addCorpus("wauchier")
self.assertEqual(Corpus.query.get(1).name, "Wauchier", "The corpus exists")
self.db.session.delete(Corpus.query.get(1))
self.db.session.commit()
self.assertEqual(Corpus.query.get(1), None, "The corpus does not exist")

def test_remove_corpus_with_custom_dict(self):
self.addCorpus("wauchier")
corpus: Corpus = Corpus.query.get(1)
self.assertEqual(corpus.name, "Wauchier", "The corpus exists")
# Add connections
corpus.custom_dictionaries_update("lemma", "test")
self.assertEqual(corpus.get_custom_dictionary("lemma", formatted=True), "test")
# Delete the corpus
self.db.session.delete(Corpus.query.get(1))
self.db.session.commit()
self.assertEqual(Corpus.query.get(1), None, "The corpus does not exist")

0 comments on commit d5d59af

Please sign in to comment.