Skip to content

copy.deepcopy() on Item fails unexpectedly #2458

Open

Description

@knoopum

Describe the bug
When attempting to make a deepcopy of an ArcGIS Item, it fails unexpectedly. The error returned varies for admin vs. regular user.

To Reproduce
Steps to reproduce the behavior:

from arcgis import GIS
import copy
gis = GIS(profile="xxxxxxxx")
item = gis.content.get('9ad056d339534fdb9c75fa354491f101')
item2 = copy.deepcopy(item)

Error returned when connecting as a regular user:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 7
      4 gis = GIS(profile="xxxxxxxx")
      6 item = gis.content.get('9ad056d339534fdb9c75fa354491f101')
----> 7 item2 = copy.deepcopy(item)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

    [... skipping similar frames: deepcopy at line 163 (3 times), _deepcopy_dict at line 222 (2 times), _reconstruct at line 260 (2 times), deepcopy at line 137 (2 times)]

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:286, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    284     for key, value in dictiter:
    285         key = deepcopy(key, memo)
--> 286         value = deepcopy(value, memo)
    287         y[key] = value
    288 else:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:262, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    260     state = deepcopy(state, memo)
    261 if hasattr(y, '__setstate__'):
--> 262     y.__setstate__(state)
    263 else:
    264     if isinstance(state, tuple) and len(state) == 2:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\site-packages\requests\adapters.py:212, in HTTPAdapter.__setstate__(self, state)
    209 for attr, value in state.items():
    210     setattr(self, attr, value)
--> 212 self.init_poolmanager(
    213     self._pool_connections, self._pool_maxsize, block=self._pool_block
    214 )

File ~\AppData\Local\ESRI\conda\envs\work\Lib\site-packages\arcgis\auth\tools\_adapter.py:239, in EsriTrustStoreAdapter.init_poolmanager(self, *args, **kwargs)
    237 def init_poolmanager(self, *args, **kwargs):
    238     """Initializes the pool manager"""
--> 239     context = self.ssl_context
    240     self.configure_ssl_context(context)
    241     kwargs["ssl_context"] = context

AttributeError: 'EsriTrustStoreAdapter' object has no attribute 'ssl_context'

Error returned when connecting as an admin user:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 7
      4 gis = GIS("home")
      6 item = gis.content.get('9ad056d339534fdb9c75fa354491f101')
----> 7 item2 = copy.deepcopy(item)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

    [... skipping similar frames: _deepcopy_dict at line 222 (3 times), _reconstruct at line 260 (3 times), deepcopy at line 163 (3 times), deepcopy at line 137 (3 times)]

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

    [... skipping similar frames: deepcopy at line 137 (1 times)]

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:202, in _deepcopy_tuple(x, memo, deepcopy)
    201 def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
--> 202     y = [deepcopy(a, memo) for a in x]
    203     # We're not going to put the tuple in the memo, but it's still important we
    204     # check for it, in case the tuple contains recursive mutable structures.
    205     try:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:163, in deepcopy(x, memo, _nil)
    161                 y = x
    162             else:
--> 163                 y = _reconstruct(x, memo, *rv)
    165 # If is its own copy, don't memoize.
    166 if y is not x:

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:260, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    258 if state is not None:
    259     if deep:
--> 260         state = deepcopy(state, memo)
    261     if hasattr(y, '__setstate__'):
    262         y.__setstate__(state)

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:137, in deepcopy(x, memo, _nil)
    135 copier = _deepcopy_dispatch.get(cls)
    136 if copier is not None:
--> 137     y = copier(x, memo)
    138 else:
    139     if issubclass(cls, type):

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:222, in _deepcopy_dict(x, memo, deepcopy)
    220 memo[id(x)] = y
    221 for key, value in x.items():
--> 222     y[deepcopy(key, memo)] = deepcopy(value, memo)
    223 return y

File ~\AppData\Local\ESRI\conda\envs\work\Lib\copy.py:152, in deepcopy(x, memo, _nil)
    150 reductor = getattr(x, "__reduce_ex__", None)
    151 if reductor is not None:
--> 152     rv = reductor(4)
    153 else:
    154     reductor = getattr(x, "__reduce__", None)

TypeError: cannot pickle 'LazyLoader' object

Expected behavior
Expect a deepcopy of an Item object to succeed.

Platform (please complete the following information):

  • ArcGIS Online
  • Python API 2.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions