Error attempting to overwrite feature layer data using Python API

1134
5
10-14-2022 06:17 AM
MichaelSnook
Occasional Contributor III

I cannot seem to overwrite a feature layer by uploading a file geodatabase via the Python API. I have triple checked and re-tried from start to finish uploading a .zipped file GDB, publishing a hosted feature service and attempt to update the file GDB with the EXACT SAME name as when I started. I throws the 'Cannot find related data item used to publish this Feature Layer' error. It works fine however if I use the tools in ArcGIS online, navigate to the same file GDB and overwrite.

 

    gis = GIS(baseurl, username, password, verify_cert=False)
gdbpath = r"c:\temp\gdb.zip' item = gis.content.get('guid') # feature layer collection fs = item.layers[0].container print(fs.manager.overwrite(gdbpath))`

I have to think there's something with how you enter the path to the gdb for it to recongnize it as the same file name. Any ideas? Thanks!

0 Kudos
5 Replies
Oliver_Burdekin
Occasional Contributor II

I've recently been doing this with geojson. I found that the feature layer collection itself was updated rather than the

item.layers[0].container

 

So with your code this would be:

gdbpath = r"c:\temp\gdb.zip'
item = gis.content.get('guid') # this is just the item
feature_layer_collection = FeatureLayerCollection.fromitem(item)
feature_layer_collection.manager.overwrite(gdbpath)

It may be different as you are dealing with a gdb here instead of geojson.

There's a sample of overwriting features in the API samples here.

0 Kudos
MichaelSnook
Occasional Contributor III

I have tried that previously with the same results...either way the .container property or the .fromitem method return the FeatureLayerCollection...which is what is needed to access the .manager.  Both ways, when calling the .overwrite method with the file path, fail with the 'Cannot find related data item used to publish this Feature Layer' error. I'm stumped.

0 Kudos
Oliver_Burdekin
Occasional Contributor II

Is there a service definition associated with the fgbd?

0 Kudos
MichaelSnook
Occasional Contributor III

No, the orginal file GDB is in my content.  I uploaded this first as a zip file with the option to publish a hosted feature layer.  Beyond that there is no SD.  I can successfully update the newly created feature layer with an updated file GDB (zipped) using the AGO tools but it just doesn't work with the script.

0 Kudos
MichaelSnook
Occasional Contributor III

I finally figured it out...it's not exactly obvious but it was staring me in the face.  The owner of the orginal dataset was a different user than the one connecting to AGO in the script.  Once I changed ownership to the connecting user it works fine!

Now, we use a data-admin user that has similar prvilages to a adminstrator but trimmed down a bit for these data managment task automations.  I would assume that this user would be able to find the original datasource (that another user owns) for the feature layer and replace it but it doesn't seem like that's the case.

I wonder if there is a setting that would allow this or if that's just how it is?

Thanks!