Skip to content

Commit

Permalink
Revert "Propagate modify time from object to containers"
Browse files Browse the repository at this point in the history
This reverts commit 3ccd69b.
  • Loading branch information
gregorjerse committed Dec 14, 2023
1 parent 62102bc commit 0402314
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 167 deletions.
3 changes: 0 additions & 3 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ Changed
authentication backend
- Use ``keys`` instead of ``scan_iter`` in ``clear`` method of ``redis`` cache,
since ``scan_iter`` is much slower
- Modified time propagates from ``Data`` object to ``Entity`` to ``Collection``
- Modified time propagates from ``AnnotationValue`` to ``Entity``
- Modified time propagates from ``Relation`` to ``Collection``
- Do not allow deleting annotation field if annotation values are present


Expand Down
3 changes: 0 additions & 3 deletions resolwe/flow/models/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from django.core.exceptions import ValidationError
from django.db import models
from django.utils.timezone import now

from resolwe.flow.models.base import BaseModel
from resolwe.permissions.models import Permission, PermissionObject
Expand Down Expand Up @@ -506,8 +505,6 @@ def save(self, *args, **kwargs):
if "label" not in self._value:
self.recompute_label()
super().save(*args, **kwargs)
self.entity.modified = now()
self.entity.save(update_fields=["modified"])

def recompute_label(self):
"""Recompute label from value and set it to the model instance."""
Expand Down
14 changes: 2 additions & 12 deletions resolwe/flow/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,6 @@ def save(self, render_name=False, *args, **kwargs):

with transaction.atomic():
self._perform_save(*args, **kwargs)
if self.entity:
self.entity.skip_auto_now = True # type: ignore
self.entity.modified = self.modified
self.entity.save(update_fields=["modified"])
self.entity.skip_auto_now = False # type: ignore
elif self.collection:
self.collection.skip_auto_now = True # type: ignore
self.collection.modified = self.modified
self.collection.save(update_fields=["modified"])
self.collection.skip_auto_now = False # type: ignore

self._original_output = self.output

Expand Down Expand Up @@ -631,7 +621,7 @@ def move_to_collection(self, collection):
self.permission_group = collection.permission_group
if collection:
self.tags = collection.tags
self.save(update_fields=["tags", "permission_group", "collection", "modified"])
self.save(update_fields=["tags", "permission_group", "collection"])

@move_to_container
def move_to_entity(self, entity):
Expand All @@ -645,7 +635,7 @@ def move_to_entity(self, entity):
else:
self.permission_group = entity.permission_group
self.tags = entity.tags
self.save(update_fields=["permission_group", "entity", "tags", "modified"])
self.save(update_fields=["permission_group", "entity", "tags"])

def validate_change_collection(self, collection):
"""Raise validation error if data object cannot change collection."""
Expand Down
14 changes: 0 additions & 14 deletions resolwe/flow/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,6 @@ def update_annotations(self, annotations: dict[str, Any], update=True):
unique_fields=["entity", "field"],
)

def save(self, *args, **kwargs):
"""Propagate the modified time to the collection."""
super().save(*args, **kwargs)
if self.collection:
self.collection.skip_auto_now = True # type: ignore
self.collection.modified = self.modified
self.collection.save(update_fields=["modified"])
self.collection.skip_auto_now = False # type: ignore


class RelationType(models.Model):
"""Model for storing relation types."""
Expand Down Expand Up @@ -557,11 +548,6 @@ def save(self, *args, **kwargs):
"`descriptor_schema` must be defined if `descriptor` is given"
)
super().save()
if self.collection:
self.collection.skip_auto_now = True # type: ignore
self.collection.modified = self.modified
self.collection.save(update_fields=["modified"])
self.collection.skip_auto_now = False # type: ignore


class RelationPartition(models.Model):
Expand Down
29 changes: 0 additions & 29 deletions resolwe/flow/tests/test_annotations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=missing-docstring
import time
from typing import Any, Sequence

from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -196,34 +195,6 @@ def test_all_fields_included(self):
self.assertIn(method_name, dir(self))


class TestModifiedPropagated(TestCase):
def test_modified_propagated(self):
"""Test modify propagates to entity."""
entity = Entity.objects.create(contributor=self.contributor)
annotation_group = AnnotationGroup.objects.create(
name="group", label="Annotation group", sort_order=1
)
field = AnnotationField.objects.create(
name="field name",
label="field label",
type=AnnotationType.STRING.value,
sort_order=1,
group=annotation_group,
)

old_modified = entity.modified
time.sleep(0.1)
value = AnnotationValue.objects.create(entity=entity, value="Test", field=field)
entity.refresh_from_db()
self.assertGreater(entity.modified, old_modified)
old_modified = entity.modified
time.sleep(0.1)
value.value = "New value"
value.save()
entity.refresh_from_db()
self.assertGreater(entity.modified, old_modified)


class TestOrderEntityByAnnotations(TestCase):
"""Test ordering Entities by annotation values."""

Expand Down
51 changes: 0 additions & 51 deletions resolwe/flow/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# pylint: disable=missing-docstring,too-many-lines
import os
import shutil
import time
from datetime import timedelta
from unittest.mock import MagicMock, PropertyMock, patch

Expand Down Expand Up @@ -311,39 +310,6 @@ def test_dependencies_list(self):
{d.kind for d in third.parents_dependency.all()}, {DataDependency.KIND_IO}
)

def test_modified_propagated(self):
"""Test modified field is propagated to the entity and collection."""
process = Process.objects.create(contributor=self.contributor)
data = Data.objects.create(contributor=self.contributor, process=process)
collection = Collection.objects.create(contributor=self.contributor)
entity = Entity.objects.create(
contributor=self.contributor, collection=collection
)
old_modified = data.modified
old_collection_modified = collection.modified
data.move_to_collection(collection)
time.sleep(0.1)
data.refresh_from_db()
collection.refresh_from_db()
self.assertGreater(data.modified, old_modified)
self.assertGreater(data.modified, old_collection_modified)
self.assertEqual(collection.modified, data.modified)

data = Data.objects.create(contributor=self.contributor, process=process)
old_modified = data.modified
old_entity_modified = entity.modified
old_collection_modified = collection.modified
time.sleep(0.1)
data.move_to_entity(entity)
data.refresh_from_db()
collection.refresh_from_db()
entity.refresh_from_db()
self.assertGreater(data.modified, old_modified)
self.assertGreater(data.modified, old_collection_modified)
self.assertGreater(data.modified, old_entity_modified)
self.assertEqual(collection.modified, data.modified)
self.assertEqual(entity.modified, data.modified)


class EntityModelTest(TestCase):
def setUp(self):
Expand All @@ -364,21 +330,6 @@ def setUp(self):
name="Test data", contributor=self.contributor, process=self.process
)

def test_modified_propagated(self):
"""Test modified field is propagated to the entity and collection."""
collection = Collection.objects.create(contributor=self.contributor)
entity = Entity.objects.create(
contributor=self.contributor, collection=collection
)
old_entity_modified = entity.modified
entity.name = "New name"
time.sleep(0.1)
entity.save()
entity.refresh_from_db()
collection.refresh_from_db()
self.assertGreater(entity.modified, old_entity_modified)
self.assertEqual(collection.modified, entity.modified)

def test_delete_data(self):
# Create another Data object and add it to the same Entity.
data_2 = Data.objects.create(
Expand Down Expand Up @@ -1777,5 +1728,3 @@ def test_referenced_mix(self):
refs.remove("jsonout.txt")
refs.remove("stdout.txt")
self.assertSetEqual(set(refs), {"file1", "file2"})
self.assertSetEqual(set(refs), {"file1", "file2"})
self.assertSetEqual(set(refs), {"file1", "file2"})
12 changes: 0 additions & 12 deletions resolwe/flow/tests/test_relations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pylint: disable=missing-docstring
import os
import time

from django.apps import apps
from django.contrib.auth.models import AnonymousUser
Expand Down Expand Up @@ -123,17 +122,6 @@ def setUp(self):
)
self.collection.set_permission(Permission.VIEW, AnonymousUser())

def test_modified_propagated(self):
"""Test modified date propagetes to collection."""
old_modified = self.collection.modified
time.sleep(0.1)
self.relation_group.contributor = self.user
self.relation_group.save()
self.collection.refresh_from_db()
self.relation_group.refresh_from_db()
self.assertGreater(self.collection.modified, old_modified)
self.assertEqual(self.relation_group.modified, self.collection.modified)

def test_prefetch(self):
self.relation_group.delete()
self.relation_series.delete()
Expand Down
56 changes: 13 additions & 43 deletions resolwe/observers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,45 +344,27 @@ def update_data():

await update_data()

updates = [json.loads(await client.receive_from()) for _ in range(6)]
updates = [json.loads(await client.receive_from()) for _ in range(3)]
self.assertCountEqual(
updates,
[
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.collection.pk,
"subscription_id": self.subscription_id.hex,
"source": ["data", data.pk],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.entity.pk,
"subscription_id": self.subscription_id.hex,
"source": ["data", data.pk],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.pk,
"subscription_id": self.subscription_id.hex,
"source": ["data", data.pk],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.entity.pk,
"object_id": 40,
"subscription_id": self.subscription_id.hex,
"source": ["entity", data.entity.pk],
"source": ["data", 42],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.collection.pk,
"object_id": 41,
"subscription_id": self.subscription_id.hex,
"source": ["entity", data.entity.pk],
"source": ["data", 42],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.collection.pk,
"object_id": 42,
"subscription_id": self.subscription_id.hex,
"source": ["collection", data.collection.pk],
"source": ["data", 42],
},
],
)
Expand All @@ -394,27 +376,21 @@ def update_entity():
entity.save()

await update_entity()
updates = [json.loads(await client.receive_from()) for _ in range(3)]
updates = [json.loads(await client.receive_from()) for _ in range(2)]
self.assertCountEqual(
updates,
[
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.collection.pk,
"subscription_id": self.subscription_id.hex,
"source": ["entity", data.entity.pk],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.entity.pk,
"object_id": 40,
"subscription_id": self.subscription_id.hex,
"source": ["entity", data.entity.pk],
"source": ["entity", 41],
},
{
"change_type": ChangeType.UPDATE.name,
"object_id": data.collection.pk,
"object_id": 41,
"subscription_id": self.subscription_id.hex,
"source": ["collection", data.collection.pk],
"source": ["entity", 41],
},
],
)
Expand Down Expand Up @@ -1303,7 +1279,7 @@ def change_permission_group(data):
json.loads(await client_bob.receive_from()) for _ in range(2)
]
notifications_alice = [
json.loads(await client_alice.receive_from()) for _ in range(4)
json.loads(await client_alice.receive_from()) for _ in range(3)
]

# Assert that Bob sees this as a deletion.
Expand All @@ -1327,12 +1303,6 @@ def change_permission_group(data):
self.assertCountEqual(
notifications_alice,
[
{
"object_id": self.collection2.pk,
"change_type": ChangeType.UPDATE.name,
"subscription_id": self.subscription_id2.hex,
"source": ["collection", self.collection2.pk],
},
{
"object_id": data.pk,
"change_type": ChangeType.UPDATE.name,
Expand Down

0 comments on commit 0402314

Please sign in to comment.