From 8b7fa1199a72133fd3dd87d148a48cf08ad033e8 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Fri, 20 Dec 2024 08:53:12 -0600 Subject: [PATCH] chore: remove single-use repair_dead_on_expire task (#8348) * chore: remove single-use repair_dead_on_expire task * fix: remove repair_dead_on_expire * chore: remove abandoned imports --- ietf/doc/expire.py | 42 ++-------------------- ietf/doc/tasks.py | 6 ---- ietf/doc/tests_draft.py | 79 +++-------------------------------------- ietf/doc/tests_tasks.py | 5 --- 4 files changed, 6 insertions(+), 126 deletions(-) diff --git a/ietf/doc/expire.py b/ietf/doc/expire.py index 57af2ad91..98554bae0 100644 --- a/ietf/doc/expire.py +++ b/ietf/doc/expire.py @@ -13,10 +13,10 @@ from pathlib import Path from typing import List, Optional # pyflakes:ignore -from ietf.doc.utils import new_state_change_event, update_action_holders +from ietf.doc.utils import update_action_holders from ietf.utils import log from ietf.utils.mail import send_mail -from ietf.doc.models import Document, DocEvent, State, StateDocEvent +from ietf.doc.models import Document, DocEvent, State from ietf.person.models import Person from ietf.meeting.models import Meeting from ietf.mailtrigger.utils import gather_address_lists @@ -235,41 +235,3 @@ def clean_up_draft_files(): # All uses of this past 2014 seem related to major system failures. move_file_to("unknown_ids") - -def repair_dead_on_expire(): - by = Person.objects.get(name="(System)") - id_exists = State.objects.get(type="draft-iesg", slug="idexists") - dead = State.objects.get(type="draft-iesg", slug="dead") - dead_drafts = Document.objects.filter( - states__type="draft-iesg", states__slug="dead", type_id="draft" - ) - for d in dead_drafts: - dead_event = d.latest_event( - StateDocEvent, state_type="draft-iesg", state__slug="dead" - ) - if dead_event is not None: - if d.docevent_set.filter(type="expired_document").exists(): - closest_expiry = min( - [ - abs(e.time - dead_event.time) - for e in d.docevent_set.filter(type="expired_document") - ] - ) - if closest_expiry.total_seconds() < 60: - d.set_state(id_exists) - events = [] - e = DocEvent( - doc=d, - rev=d.rev, - type="added_comment", - by=by, - desc="IESG Dead state was set due only to document expiry - changing IESG state to ID-Exists", - ) - e.skip_community_list_notification = True - e.save() - events.append(e) - e = new_state_change_event(d, by, dead, id_exists) - e.skip_community_list_notification = True - e.save() - events.append(e) - d.save_with_history(events) diff --git a/ietf/doc/tasks.py b/ietf/doc/tasks.py index b7f89e1f9..f1de459dd 100644 --- a/ietf/doc/tasks.py +++ b/ietf/doc/tasks.py @@ -18,7 +18,6 @@ from .expire import ( in_draft_expire_freeze, get_expired_drafts, expirable_drafts, - repair_dead_on_expire, send_expire_notice_for_draft, expire_draft, clean_up_draft_files, @@ -62,11 +61,6 @@ def expire_ids_task(): raise -@shared_task -def repair_dead_on_expire_task(): - repair_dead_on_expire() - - @shared_task def notify_expirations_task(notify_days=14): for doc in get_soon_to_expire_drafts(notify_days): diff --git a/ietf/doc/tests_draft.py b/ietf/doc/tests_draft.py index 84959625c..240580668 100644 --- a/ietf/doc/tests_draft.py +++ b/ietf/doc/tests_draft.py @@ -19,10 +19,10 @@ from django.utils.html import escape import debug # pyflakes:ignore -from ietf.doc.expire import expirable_drafts, get_expired_drafts, repair_dead_on_expire, send_expire_notice_for_draft, expire_draft -from ietf.doc.factories import EditorialDraftFactory, IndividualDraftFactory, StateDocEventFactory, WgDraftFactory, RgDraftFactory, DocEventFactory +from ietf.doc.expire import expirable_drafts, get_expired_drafts, send_expire_notice_for_draft, expire_draft +from ietf.doc.factories import EditorialDraftFactory, IndividualDraftFactory, WgDraftFactory, RgDraftFactory, DocEventFactory from ietf.doc.models import ( Document, DocReminder, DocEvent, - ConsensusDocEvent, LastCallDocEvent, RelatedDocument, State, StateDocEvent, TelechatDocEvent, + ConsensusDocEvent, LastCallDocEvent, RelatedDocument, State, TelechatDocEvent, WriteupDocEvent, DocRelationshipName, IanaExpertDocEvent ) from ietf.doc.utils import get_tags_for_stream_id, create_ballot_if_not_open from ietf.doc.views_draft import AdoptDraftForm @@ -36,7 +36,7 @@ from ietf.iesg.models import TelechatDate from ietf.utils.test_utils import login_testing_unauthorized from ietf.utils.mail import outbox, empty_outbox, get_payload_text from ietf.utils.test_utils import TestCase -from ietf.utils.timezone import date_today, datetime_today, datetime_from_date, DEADLINE_TZINFO +from ietf.utils.timezone import date_today, datetime_from_date, DEADLINE_TZINFO class ChangeStateTests(TestCase): @@ -845,77 +845,6 @@ class ExpireIDsTests(DraftFileMixin, TestCase): self.assertTrue(not os.path.exists(os.path.join(settings.INTERNET_DRAFT_PATH, txt))) self.assertTrue(os.path.exists(os.path.join(settings.INTERNET_DRAFT_ARCHIVE_DIR, txt))) - @mock.patch("ietf.community.signals.notify_of_event") - def test_repair_dead_on_expire(self, mock_notify): - - # Create a draft in iesg idexists - ensure it doesn't get new docevents. - # Create a draft in iesg dead with no expires within the window - ensure it doesn't get new docevents and its state doesn't change. - # Create a draft in iesg dead with an expiry in the window - ensure it gets the right doc events, iesg state changes, draft state doesn't change. - last_year = datetime_today() - datetime.timedelta(days=365) - - not_dead = WgDraftFactory(name="draft-not-dead") - not_dead_event_count = not_dead.docevent_set.count() - - dead_not_from_expires = WgDraftFactory(name="draft-dead-not-from-expiring") - dead_not_from_expires.set_state( - State.objects.get(type="draft-iesg", slug="dead") - ) - StateDocEventFactory( - doc=dead_not_from_expires, state=("draft-iesg", "dead"), time=last_year - ) - DocEventFactory( - doc=dead_not_from_expires, - type="expired_document", - time=last_year + datetime.timedelta(days=1), - ) - dead_not_from_expires_event_count = dead_not_from_expires.docevent_set.count() - - dead_from_expires = [] - dead_from_expires_event_count = dict() - for delta in [-5, 5]: - d = WgDraftFactory( - name=f"draft-dead-from-expiring-just-{'before' if delta<0 else 'after'}" - ) - d.set_state(State.objects.get(type="draft-iesg", slug="dead")) - StateDocEventFactory(doc=d, state=("draft-iesg", "dead"), time=last_year) - DocEventFactory( - doc=d, - type="expired_document", - time=last_year + datetime.timedelta(seconds=delta), - ) - dead_from_expires.append(d) - dead_from_expires_event_count[d] = d.docevent_set.count() - - notified_during_factory_work = mock_notify.call_count - for call_args in mock_notify.call_args_list: - e = call_args.args[0] - self.assertTrue(isinstance(e,DocEvent)) - self.assertFalse(hasattr(e,"skip_community_list_notification")) - - repair_dead_on_expire() - - self.assertEqual(not_dead.docevent_set.count(), not_dead_event_count) - self.assertEqual( - dead_not_from_expires.docevent_set.count(), - dead_not_from_expires_event_count, - ) - for d in dead_from_expires: - self.assertEqual( - d.docevent_set.count(), dead_from_expires_event_count[d] + 2 - ) - self.assertIn( - "due only to document expiry", d.latest_event(type="added_comment").desc - ) - self.assertEqual( - d.latest_event(StateDocEvent).desc, - "IESG state changed to I-D Exists from Dead", - ) - self.assertEqual(mock_notify.call_count, 4+notified_during_factory_work) - for call_args in mock_notify.call_args_list[-4:]: - e = call_args.args[0] - self.assertTrue(isinstance(e,DocEvent)) - self.assertTrue(hasattr(e,"skip_community_list_notification")) - self.assertTrue(e.skip_community_list_notification) class ExpireLastCallTests(TestCase): def test_expire_last_call(self): diff --git a/ietf/doc/tests_tasks.py b/ietf/doc/tests_tasks.py index 135b52f60..67997acd8 100644 --- a/ietf/doc/tests_tasks.py +++ b/ietf/doc/tests_tasks.py @@ -21,7 +21,6 @@ from .tasks import ( generate_idnits2_rfcs_obsoleted_task, generate_idnits2_rfc_status_task, notify_expirations_task, - repair_dead_on_expire_task, ) class TaskTests(TestCase): @@ -99,10 +98,6 @@ class TaskTests(TestCase): self.assertEqual(mock_expire.call_args_list[1], mock.call(docs[1])) self.assertEqual(mock_expire.call_args_list[2], mock.call(docs[2])) - @mock.patch("ietf.doc.tasks.repair_dead_on_expire") - def test_repair_dead_on_expire_task(self, mock_repair): - repair_dead_on_expire_task() - self.assertEqual(mock_repair.call_count, 1) class Idnits2SupportTests(TestCase): settings_temp_path_overrides = TestCase.settings_temp_path_overrides + ['DERIVED_DIR']