Skip to content

Commit

Permalink
update instance date_modified when deleting instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Nov 18, 2024
1 parent 7a02f60 commit 9f28dcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion onadata/libs/tests/utils/test_logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ def test_hard_delete_subset(self):
self.assertEqual(self.xform.num_of_submissions, 3)

def test_sets_deleted_at(self):
"""Deleted_at is set to the current time"""
"""deleted_at is set to the current time"""
mocked_now = timezone.now()

with patch("django.utils.timezone.now", Mock(return_value=mocked_now)):
Expand All @@ -1094,6 +1094,17 @@ def test_sets_deleted_at(self):
all(instance.deleted_at == mocked_now for instance in self.instances)
)

def test_sets_date_modified(self):
"""date_modified is set to the current time"""
mocked_now = timezone.now()

with patch("django.utils.timezone.now", Mock(return_value=mocked_now)):
delete_xform_submissions(self.xform)

self.assertTrue(
all(instance.date_modified == mocked_now for instance in self.instances)
)

def test_sets_deleted_by(self):
"""Deleted_by is set to the user who initiated the deletion"""
delete_xform_submissions(self.xform, deleted_by=self.user)
Expand Down
3 changes: 2 additions & 1 deletion onadata/libs/utils/logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@ def delete_xform_submissions(
instances = xform.instances.filter(deleted_at__isnull=True)

if soft_delete:
instances.update(deleted_at=timezone.now(), deleted_by=deleted_by)
now = timezone.now()
instances.update(deleted_at=now, date_modified=now, deleted_by=deleted_by)
else:
# Hard delete
instances.delete()
Expand Down

0 comments on commit 9f28dcf

Please sign in to comment.