Esri / Esri/arcgis-python-api

Double fetching of a group when searching for groups

オープン
#2,437 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
2.2k
フォーク
1.2k
平均マージ
2時間 40分
マージ済み PR(30日)
2

説明

When searching for groups the created class is not set properly which cause the group to be fetched a second time when accessing a property.

**To Reproduce**
Search the groups of an organization
```python
target_portal_groups = gis.groups.search("*", sort_field="title", max_groups=1000)
```
error:
```python
target_portal_groups[0].title # This will query the portal
```

**Expected behavior**
The dictionnary from the initial fetch you be used instead of fetching the object again.

**Platform (please complete the following information):**
- OS: WIndows 11
- Python API Version: 2.4.2

**Additional context**
The reason why this happens is the Group object `hydrate` property is not set correctly when the group dict was provided on initialization.

```python
def __init__(self, gis, groupid, groupdict=None):
dict.__init__(self)
self._gis = gis
self._migrate = None
self._portal = gis._portal
self.groupid = groupid
self.thumbnail = None
self._workdir = tempfile.gettempdir()
# groupdict = self._portal.get_group(self.groupid)
self._hydrated = False
if groupdict:
groupdict.update(self.__dict__)
super(Group, self).update(groupdict)
```

When the groupdict is provided it updates the group dict with it's properties. But since it doesn't set hydrated to true it will fetch its properties later on.

```python
def __getattr__(self, name):
if not self._hydrated and not name.startswith("_"):
self._hydrate()
if name.startswith("_ipython_"):
return None # Skip IPython-specific attributes
try:
return dict.__getitem__(self, name)
except AttributeError:
raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))
```

If we look at the hydrate function it actually does pretty much the same thing as the initial group creation but it correctly sets the hydrate property.

```python
def _hydrate(self):
try:
groupdict = self._portal.get_group(self.groupid)
self._hydrated = True
super(Group, self).update(groupdict)
self.__dict__.update(groupdict)
except Exception as e:
raise e
```

I've checked on my side and the initial call to search the groups returns all the properties of the group (which can be seen when reading the rest api documentation).

https://developers.arcgis.com/rest/users-groups-and-items/group-search/
Returns: A JSON array of group objects. See the response properties for [Group](https://developers.arcgis.com/rest/users-groups-and-items/group/).

This is kinda a big bug on our side this will causes a lot of fetches to our organization.

Thanks,
Mathieu

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Group.__init__ と groups.search のパスから始め、そこで groupdict が _hydrate とどのように適用されているかを比較します。再現された検索例と target_portal_groups[0].title へのアクセスを検証します。完了条件は、2 回目のポータルクエリなしで初期のグループデータが使用されることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api, backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。