Просмотр исходного кода

don't delete topics when they are removed from topictracker

micha 7 лет назад
Родитель
Сommit
9f434f3d90
2 измененных файлов с 17 добавлено и 1 удалено
  1. 0 1
      flaskbb/user/models.py
  2. 17 0
      tests/unit/test_forum_models.py

+ 0 - 1
flaskbb/user/models.py

@@ -156,7 +156,6 @@ class User(db.Model, UserMixin, CRUDMixin):
         primaryjoin=(topictracker.c.user_id == id),
         primaryjoin=(topictracker.c.user_id == id),
         backref=db.backref("topicstracked", lazy="dynamic"),
         backref=db.backref("topicstracked", lazy="dynamic"),
         lazy="dynamic",
         lazy="dynamic",
-        cascade="all, delete-orphan",
         single_parent=True
         single_parent=True
     )
     )
 
 

+ 17 - 0
tests/unit/test_forum_models.py

@@ -401,6 +401,23 @@ def test_topic_tracker_needs_update(database, user, topic):
         assert topic.tracker_needs_update(forumsread, topicsread)
         assert topic.tracker_needs_update(forumsread, topicsread)
 
 
 
 
+def test_untracking_topic_does_not_delete_it(database, user, topic):
+    user.track_topic(topic)
+    user.save()
+    user.untrack_topic(topic)
+
+    # Note that instead of returning None from the query below, the
+    # unpatched verson will actually raise a DetachedInstanceError here,
+    # due to the fact that some relationships don't get configured in
+    # tests correctly and deleting would break them or something.  The
+    # test still fails for the same reason, however: the topic gets
+    # (albeit unsuccessfully) deleted when it is removed from
+    # topictracker, when it clearly shouldn't be.
+    user.save()
+
+    assert Topic.query.filter(Topic.id == topic.id).first()
+
+
 def test_topic_tracker_needs_update_cleared(database, user, topic):
 def test_topic_tracker_needs_update_cleared(database, user, topic):
     """Tests if the topicsread needs an update if the forum has been marked
     """Tests if the topicsread needs an update if the forum has been marked
     as cleared.
     as cleared.