Skip to content

Commit 008d61f

Browse files
Merge pull request #1317 from hinashi/change/edit_entity/update_es
Changed to not update ElasticSearch when editing entity
2 parents 7de59dd + d0b63e1 commit 008d61f

File tree

3 files changed

+0
-104
lines changed

3 files changed

+0
-104
lines changed

entity/tasks.py

-31
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ def edit_entity(self, job: Job) -> JobStatus:
8080
entity.note = recv_data["note"]
8181
entity.save(update_fields=["note"])
8282

83-
# This describes job pamraeters of Job.update_es_docuemnt()
84-
jp_update_es_document = {
85-
"is_updated": True,
86-
}
87-
8883
# update processing for each attrs
8984
deleted_attr_ids = []
9085
for attr in recv_data["attrs"]:
@@ -156,27 +151,6 @@ def edit_entity(self, job: Job) -> JobStatus:
156151
# register History to register adding EntityAttr
157152
history.add_attr(attr_obj)
158153

159-
Job.new_update_documents(entity, "", jp_update_es_document).run()
160-
161-
# This job updates elasticsearch not only Entries that are belonged to
162-
# the edited Entity, but also Entrie that are refered by Entry, which is
163-
# belonged to this Entity.
164-
associated_entity_ids = set()
165-
for attr in entity.attrs.filter(is_active=True):
166-
associated_entity_ids |= set([x.id for x in attr.referral.filter(is_active=True)])
167-
168-
# This also update es-documents of Entries that are referred by AttributeValues
169-
# that are associated with deleted EntityAttrs.
170-
for attr_id in deleted_attr_ids:
171-
attr = EntityAttr.objects.filter(id=attr_id).last()
172-
if attr:
173-
associated_entity_ids |= set([x.id for x in attr.referral.filter(is_active=True)])
174-
175-
# create job to update es-document that is related with edited Entity
176-
for related_entity_id in associated_entity_ids:
177-
related_entity = Entity.objects.get(id=related_entity_id)
178-
Job.new_update_documents(related_entity, "", jp_update_es_document).run()
179-
180154
# clear flag to specify this entity has been completed to edit
181155
entity.del_status(Entity.STATUS_EDITING)
182156

@@ -239,11 +213,6 @@ def edit_entity_v2(self, job: Job) -> JobStatus:
239213

240214
serializer.update_remaining(entity, serializer.validated_data)
241215

242-
jp_update_es_document = {
243-
"is_updated": True,
244-
}
245-
Job.new_update_documents(entity, "", jp_update_es_document).run()
246-
247216
return JobStatus.DONE
248217

249218

entity/tests/test_api_v2.py

-50
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
from rest_framework.exceptions import ValidationError
1313

1414
from acl.models import ACLBase
15-
from airone.lib.elasticsearch import AttrHint
1615
from airone.lib.log import Logger
1716
from airone.lib.test import AironeViewTest
1817
from airone.lib.types import AttrType
1918
from entity import tasks
2019
from entity.models import Entity, EntityAttr
21-
from entry import tasks as entry_tasks
2220
from entry.models import Entry
23-
from entry.services import AdvancedSearchService
2421
from entry.tasks import create_entry_v2
2522
from group.models import Group
2623
from role.models import Role
@@ -3628,50 +3625,3 @@ def test_create_entry_when_trigger_is_set(self):
36283625
self.assertEqual(
36293626
[x.value for x in entry.get_attrv("vals").data_array.all()], ["fuga", "piyo"]
36303627
)
3631-
3632-
@mock.patch("entity.tasks.edit_entity_v2.delay", mock.Mock(side_effect=tasks.edit_entity_v2))
3633-
@mock.patch(
3634-
"entry.tasks.update_es_documents.delay",
3635-
mock.Mock(side_effect=entry_tasks.update_es_documents),
3636-
)
3637-
def test_attr_add_remove_bug(self):
3638-
user = self.admin_login()
3639-
self.add_entry(
3640-
self.user,
3641-
"test_Entry",
3642-
self.entity,
3643-
values={
3644-
"val": "hoge",
3645-
"vals": ["hoge"],
3646-
},
3647-
)
3648-
# Get the entity attribute to be deleted
3649-
entity_attr: EntityAttr = self.entity.attrs.get(name="val", is_active=True)
3650-
# Prepare parameters to add the attribute back
3651-
params = {
3652-
"attrs": [{"id": entity_attr.id, "is_deleted": True}],
3653-
}
3654-
# Send a request to delete the specified attribute
3655-
resp = self.client.put(
3656-
"/entity/api/v2/%d/" % self.entity.id, json.dumps(params), "application/json"
3657-
)
3658-
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
3659-
3660-
params = {
3661-
"attrs": [
3662-
{
3663-
"name": "val",
3664-
"type": AttrType.STRING,
3665-
},
3666-
],
3667-
}
3668-
resp = self.client.put(
3669-
"/entity/api/v2/%d/" % self.entity.id, json.dumps(params), "application/json"
3670-
)
3671-
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
3672-
3673-
# Perform a search for entries to verify the state of attributes
3674-
resp1 = AdvancedSearchService.search_entries(user, [self.entity.id], [AttrHint(name="val")])
3675-
3676-
# Validate that the actual value matches the expected value
3677-
self.assertEqual(resp1.ret_values[0].attrs["val"]["value"], "")

entity/tests/test_view.py

-23
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from entity.models import Entity, EntityAttr
1414
from entity.settings import CONFIG
1515
from entry.models import Attribute, Entry
16-
from entry.services import AdvancedSearchService
1716
from entry.tasks import update_es_documents
1817
from user.models import History, User
1918

@@ -620,19 +619,6 @@ def test_post_edit_after_creating_entry(self):
620619
self.assertEqual(entity.attrs.count(), 3)
621620
self.assertEqual(entry.attrs.count(), 2)
622621

623-
res = AdvancedSearchService.search_entries(user, [entity.id], is_output_all=True)
624-
self.assertEqual(
625-
sorted([x for x in res.ret_values[0].attrs.keys()]), sorted(["foo", "bar", "ref"])
626-
)
627-
628-
# Check the elasticsearch data is also changed when
629-
# referred Entity name is changed.
630-
res = AdvancedSearchService.search_entries(
631-
user, [ref_entity.id], hint_referral="", is_output_all=True
632-
)
633-
self.assertEqual(res.ret_count, 1)
634-
self.assertEqual(res.ret_values[0].referrals[0]["schema"]["name"], "Changed-Entity")
635-
636622
def test_post_edit_attribute_type(self):
637623
user = self.admin_login()
638624

@@ -962,15 +948,6 @@ def test_post_delete_attribute(self):
962948
self.assertEqual(History.objects.filter(operation=History.MOD_ENTITY).count(), 2)
963949
self.assertEqual(History.objects.filter(operation=History.DEL_ATTR).count(), 1)
964950

965-
# Check the elasticsearch data (the referrals parameter) is also removed when
966-
# referring EntityAttr is deleted.
967-
res = AdvancedSearchService.search_entries(
968-
user, [ref_entity.id], hint_referral="", is_output_all=True
969-
)
970-
self.assertEqual(res.ret_count, 1)
971-
self.assertEqual(res.ret_values[0].entry["id"], ref_entry.id)
972-
self.assertEqual(res.ret_values[0].referrals, [])
973-
974951
# checks for HistoricalRecord for EntityAttr,
975952
# it's value must be increased by 1, that are for delete attribute
976953
self.assertEqual(attr.history.count(), self._test_data["attr_history_count"]["before"] + 1)

0 commit comments

Comments
 (0)