Skip to content

Commit 94f9bba

Browse files
Merge pull request #1229 from hinashi/fixed/advanced_search/multi_entity
Fixed search_entries when specified multi entity
2 parents 47ca9db + bd644f7 commit 94f9bba

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

entry/models.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
from collections.abc import Iterable
3+
from copy import deepcopy
34
from datetime import date, datetime
45
from typing import Any, List, Optional, Type
56

@@ -2238,11 +2239,12 @@ def search_entries(
22382239
if "status" in resp and resp["status"] == 404:
22392240
continue
22402241

2242+
tmp_hint_attrs = deepcopy(hint_attrs)
22412243
# Check for has permission to EntityAttr, when is_output_all flag
22422244
if is_output_all:
22432245
for entity_attr in entity.attrs.filter(is_active=True):
2244-
if entity_attr.name not in [x["name"] for x in hint_attrs if "name" in x]:
2245-
hint_attrs.append(
2246+
if entity_attr.name not in [x["name"] for x in tmp_hint_attrs if "name" in x]:
2247+
tmp_hint_attrs.append(
22462248
{
22472249
"name": entity_attr.name,
22482250
"is_readable": True
@@ -2258,7 +2260,7 @@ def search_entries(
22582260
search_result = make_search_results(
22592261
user,
22602262
resp,
2261-
hint_attrs,
2263+
tmp_hint_attrs,
22622264
hint_referral,
22632265
limit,
22642266
)

entry/tests/test_model.py

+17
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,23 @@ def test_search_entries_with_is_output_all(self):
44304430
)
44314431
self.assertEqual(ret.ret_count, 0)
44324432

4433+
# multi entity case
4434+
test_entity = self.create_entity(
4435+
self._user, "test_entity", [{"name": "attr", "type": AttrType.STRING}]
4436+
)
4437+
self.add_entry(self._user, "test_entry", test_entity, {"attr": "fuga"})
4438+
ret = Entry.search_entries(
4439+
self._user, [self._entity.id, test_entity.id], is_output_all=True
4440+
)
4441+
self.assertEqual(
4442+
ret.ret_values[0].attrs,
4443+
{"attr": {"value": "hoge", "is_readable": True, "type": 2}},
4444+
)
4445+
self.assertEqual(
4446+
ret.ret_values[1].attrs,
4447+
{"attr": {"value": "fuga", "is_readable": True, "type": 2}},
4448+
)
4449+
44334450
def test_search_entries_with_offset(self):
44344451
entities = []
44354452
for i in range(3):

0 commit comments

Comments
 (0)