Double fetching of a group when searching for groups
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start at Group.init and the groups.search path, then compare how groupdict is applied there with _hydrate. Verify the reproduced search example and access to target_portal_groups[0].title; done means the initial group data is used without a second portal query.
Written by the indexing model from the issue text.
Description
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
target_portal_groups = gis.groups.search("*", sort_field="title", max_groups=1000)
error:
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.
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.
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.
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.
This is kinda a big bug on our side this will causes a lot of fetches to our organization.
Thanks,
Mathieu
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 1.1k
- Avg merge
- 2h 40m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Esri/arcgis-python-api
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Esri/arcgis-python-api#2513 · 1 comment ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Esri/arcgis-python-api#2453 · 3 comments ·
-
documentation enhancement
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Esri/arcgis-python-api#2097 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 58/100
Esri/arcgis-python-api#2537 · 3 comments ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 56/100
Esri/arcgis-python-api#2531 · 1 comment ·
All issues in Esri/arcgis-python-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100