After publishing a hosted service based on a gdb we would like to regulerly update the service using the overwrite functionality in Python API 1.4.1.
This works fine if the service resides in AGOL, but when trying the same in Portal the API throws an error. Apparently the FeatureLayerCollectionManager calls an unimplemented method: _overwrite_portal.
Traceback (most recent call last): File "c:\test\overwrite.py", line 19, in <module> _fcoll.manager.overwrite(_data) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\managers.py", line 1030, in overwrite return self._overwrite_portal(data=data_file) AttributeError: 'FeatureLayerCollectionManager' object has no attribute '_overwrite_portal
In managers.py this is implemented as this, which also explains the difference between AGOL and Enterprise:
Hi, Craig
it was a bug in the 1.4.1 ArcGIS Python API. The missing function was fixed in 1.4.2, but additional bugs made the functionality unusable until 1.5.1.
Have you updated the ArcGIS API to the latest version?
Håkon,
I had not done that. I didn't realize the API doesn't get updated when ArcGIS Pro gets updated, or that I had to do it manually.
I took your suggestion, and it's working now.
Thank you!
I spoke too soon. My errors went away, but I'm not seeing any updates in the portal layer. The feature count stays the same, and the dates don't change. I do, now, have the latest version of the API installed, but is there anything else? Is there a patch for Portal or Datastore I need to use?
Too bad, but don't think there are any specific patches needed. I just tested the API 1.5.2 on an unpatched 10.6 Portal and it worked nicely. Could you share your code or tell a bit more about your scenario?
Håkon- thanks for responding.
I wonder if I'm missing something in the script, then. Here's what I have:
from arcgis.gis import GIS,Item,User from arcgis.features import FeatureLayer Collection from datetime import datetime as dt import os,getpass s_time=dt.now() print('Started at: ' + str(s_time)) try: gis=GIS('https://portal.myportal.org/portal',username='gisadmin',password='mypassword') user=User(gis,'gisadmin',None) for item in user.items(): if item['title'] == 'Feature service overwrite test': if item['type'] == 'Feature Service': my_item = item print("overwriting '{0}'".format(my_item['title'])) my_flayer_collection = FeatureLayerCollection.fromitem(my_item) update_src = 'C:\\Users\\' + getpass.getuser() + '\\Documents\\ArcGIS\\overwrite_test.gdb\\overwrite_data' my_flayer_collection.manager.overwrite(update_src) f_time=dt.now() print('successfully updated {0} at {1}'.format(my_item['title'],str(f_time))) print('time elapsed: ' + str(f_time-s_time)) except Exception: print(str(sys.exc_info()[1]))
I appreciate your help with this! Thanks
Hi, Craig
finally had a look at your code. My guess is that your problem is the update_src.
update_src = 'C:\\Users\\' + getpass.getuser() + '\\Documents\\ArcGIS\\overwrite_test.gdb\\overwrite_data'
my_flayer_collection.manager.overwrite(update_src)
The overwrite function expects a zipped geodatabase, not a feature class, so try zipping the gdb.
Thanks, Håkon.
I gave that a try, but this time I got a "Job failed" message. The geodatabase I zipped only contains a single feature class, and it exactly matches the feature service I'm trying to update.
Is there anything special I need to do with the geodatabase, or any other ideas? I appreciate your help!
Thanks again!
Hi, hard to tell what causes the problem. If it may be to any help I've uploaded my test script and two tiny gdb's here. Just unpack the zip and edit Portal and Path info.
Håkon Dreyer - thanks..
While I was trying these solutions, I was simultaneously working with ESRI Support, and we came up with a different workflow which publishes a new SD file. That is working well, so I won't need to pursue this solution, though it appears it would be a simpler script.
Thanks for your help!