Skip to content

TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer' when trying to create Map object from arcgis.map #2287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shiyuding09 opened this issue May 16, 2025 · 1 comment
Labels

Comments

@shiyuding09
Copy link

shiyuding09 commented May 16, 2025

Describe the bug

when I tried to initalize a Map object from an Item object for one certain webmap, it raises the exception TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer', but for other webmaps, this function works well. The arcgis version I'm using is 2.4.0

To Reproduce
Steps to reproduce the behavior:

from arcgis.map import Map
from arcgis.gis import GIS 

wmap_object = gis.content.get(wmap_id)
wmap = Map(wmap_object)

error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 1
----> 1 wmap = Map(web_map_item)

File c:\Users\User1\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\Lib\site-packages\arcgis\map\map_widget.py:254, in Map.__init__(self, location, item, gis, **kwargs)
    250 self._helper._setup_gis_properties(gis)
    252 # Set up the map that will be used
    253 # either existing or new instance
--> 254 self._setup_webmap_properties(item)
    256 # Assign the definition to helper class. This is the pydantic dataclass.
    257 self._helper._set_widget_definition(self._webmap)

File c:\Users\User1\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\Lib\site-packages\arcgis\map\map_widget.py:447, in Map._setup_webmap_properties(self, item)
    435     self._webmap = ws.Webmap(
    436         operationalLayers=[],
    437         baseMap=basemap,
   (...)
    444         },  # gets fixed later in _setup_location_properties
    445     )
    446 # Set so widget gets initialized with webmap dict
--> 447 self._update_source()

File c:\Users\User1\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\Lib\site-packages\arcgis\map\map_widget.py:488, in Map._update_source(self)
    487 def _update_source(self):
--> 488     self._webmap_dict = self._webmap.dict()

File c:\Users\User1\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\Lib\site-packages\arcgis\map\_dataclasses\_webmap_spec.py:73, in BaseModel.dict(self, mode, include, exclude, by_alias, exclude_unset, exclude_defaults, exclude_none, round_trip, warnings)
     60 def dict(
     61     self,
     62     *,
   (...)
     71     warnings: bool = False,
     72 ) -> dict[str, Any]:
---> 73     d = super().model_dump(
     74         mode=mode,
     75         include=include,
     76         exclude=exclude,
     77         by_alias=by_alias,
     78         exclude_unset=exclude_unset,
     79         exclude_defaults=exclude_defaults,
     80         exclude_none=exclude_none,
     81         round_trip=round_trip,
     82         warnings=warnings,
     83     )
     85     return self._handle_enums(d)

File c:\Users\User1\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\Lib\site-packages\pydantic\main.py:308, in BaseModel.model_dump(self, mode, include, exclude, by_alias, exclude_unset, exclude_defaults, exclude_none, round_trip, warnings)
    275 def model_dump(
    276     self,
    277     *,
   (...)
    286     warnings: bool = True,
    287 ) -> dict[str, Any]:
    288     """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
    289 
    290     Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
   (...)
    306         A dictionary representation of the model.
    307     """
--> 308     return self.__pydantic_serializer__.to_python(
    309         self,
    310         mode=mode,
    311         by_alias=by_alias,
    312         include=include,
    313         exclude=exclude,
    314         exclude_unset=exclude_unset,
    315         exclude_defaults=exclude_defaults,
    316         exclude_none=exclude_none,
    317         round_trip=round_trip,
    318         warnings=warnings,
    319     )

TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer'

Screenshots
If applicable, add screenshots to help explain your problem.

Expected behavior
A clear and concise description of what you expected to happen.

Platform (please complete the following information):

  • Python API Version [2.4.0]

Additional context
Add any other context about the problem here, attachments etc.

@nanaeaubry
Copy link
Contributor

@shiyuding09
You can try upgrading to the latest version of the API and also specify the item keyword when creating the map since it is the second argument in the method.

Map(item=<item or item id>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants