This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/master by this push:
     new 3974e65f6 fully delete history snapshots when deleting artifacts (incl 
remove from solr)
3974e65f6 is described below

commit 3974e65f6cd426785ac84ae7fa9af1043ed71499
Author: Dillon Walls <[email protected]>
AuthorDate: Fri Nov 10 16:11:23 2023 +0000

    fully delete history snapshots when deleting artifacts (incl remove from 
solr)
---
 Allura/allura/model/artifact.py            |  5 +++--
 Allura/allura/tests/model/test_artifact.py | 23 +++++++++++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 3527b1d48..efb345739 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -705,9 +705,10 @@ class VersionedArtifact(Artifact):
 
     def delete(self):
         # remove history so that the snapshots aren't left orphaned
-        super().delete()
         HC = self.__mongometa__.history_class
-        HC.query.remove(dict(artifact_id=self._id))
+        for version in HC.query.find(dict(artifact_id=self._id)):
+            version.delete()
+        super().delete()
 
     @classmethod
     def is_limit_exceeded(cls, *args, **kwargs):
diff --git a/Allura/allura/tests/model/test_artifact.py 
b/Allura/allura/tests/model/test_artifact.py
index d62c01cd5..aed8add97 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -21,8 +21,8 @@ Model tests for artifact
 import re
 from datetime import datetime
 
-from tg import tmpl_context as c
-from mock import patch
+from tg import tmpl_context as c, app_globals as g
+from mock import patch, Mock
 import pytest
 from ming.odm.odmsession import ThreadLocalODMSession
 from ming.odm import Mapper
@@ -145,6 +145,7 @@ class TestArtifact:
         assert re.match(r'%[email protected]' %
                         str(p._id), p.message_id())
 
+    @patch('allura.tasks.mail_tasks.sendmail', Mock())
     def test_versioning(self):
         pg = WM.Page(title='TestPage3')
         with patch('allura.model.artifact.request', Request.blank('/', 
remote_addr='1.1.1.1')):
@@ -171,6 +172,24 @@ class TestArtifact:
         assert ss.text != pg.text
         assert pg.history().count() == 3
 
+        _id = pg._id
+        M.MonQTask.run_ready()
+        assert g.solr.search('id:' + pg.index_id()).hits == 1
+        ph = WM.PageHistory.query.find({'artifact_id': _id, 'version': 
2}).first()
+        assert ph
+        ph_index = ph.index_id()
+        solr_hist = g.solr.search('id:' + ph_index)
+        if not solr_hist:  # sometimes history doesn't get added to solr
+            g.solr.add([ph.solarize()])
+            g.solr.commit()
+        assert g.solr.search('id:' + ph_index).hits == 1
+        pg.delete()
+        ThreadLocalODMSession.flush_all()
+        M.MonQTask.run_ready()
+        WM.PageHistory.query.find({'artifact_id': _id}).count() == 0
+        # history should be deleted from solr
+        assert g.solr.search('id:' + ph_index).hits == 0
+
     def test_messages_unknown_lookup(self):
         from bson import ObjectId
         m = Checkmessage()

Reply via email to