Python API Bug? arcgis.features.FeatureLayer.edit_features(adds=[ftSet_array]) throws 10500 Error

1231
3
03-02-2023 04:50 PM
EmmaHatcher
Occasional Contributor

Hello,

I am trying to automate updates of a hosted feature service in Portal 10.8.1. I have a method to convert the feature class to a feature set, then pass the array of features from that feature set to the arcgis.features.FeatureLayer.edit_features(adds=[ftSet_array]). This function when run using a Portal feature service doesn't append any data. When I print the edit result, I see the following message:

{'addResults': [{'objectId': None, 'success': False, 'error': {'code': 10500, 'description': 'class org.json.JSONObject cannot be cast to class com.esri.core.geometry.Geometry (org.json.JSONObject and com.esri.core.geometry.Geometry are in unnamed module of loader java.net.URLClassLoader @614ddd49)'}}], 'updateResults': [], 'deleteResults': [], 'attachments': {'addResults': [], 'updateResults': [], 'deleteResults': []}}

The exact same script/code works and appends the data as expected and incredibly fast/efficiently on a copy of the hosted feature service in ArcGIS Online. 

In the snippet below, I converted a feature class to a feature set called add_features. 

 

adds_array = []
        for a in add_features:
            adds_array.append(a)

        total_adds = len(adds_array)
        if total_adds > 10000:
            print_to_stdout("Incrementally appending new data...")
            n = 10000
            inc_adds_array = [adds_array[i * n:(i + 1) * n] for i in range((len(adds_array) + n - 1) // n )]
            for lst in inc_adds_array:
                #print(lst)
                edit_result = target_ftlyr.edit_features(adds=lst)
                print("Edits summary: {0}".format(edit_result))
            print("{0} total features successfully added to the feature service!".format(total_adds))
        else:
            edit_result = target_ftlyr.edit_features(adds=adds_array)
            print({0} total features successfully added to the feature service!".format(str(len(adds_array))))

 

Is the FeatureLayer.edit_features() only available in ArcGIS Online?

0 Kudos
3 Replies
Kepa
by Esri Contributor
Esri Contributor

Hello @EmmaHatcher,

I think in terms of efficiency I wouldn't go through the feature class to feature set conversion. You just can call append method from the FeatureLayer object uploading the feature class directly. If I'm not mistaken it's supported since version 10.8.1.

Regards,

JakeSkinner
Esri Esteemed Contributor

Hi Emma, 

I second Kepa's idea of using the append method.  Take a look at the following script.  It may give you what you need. 

https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/...

0 Kudos
EmmaHatcher
Occasional Contributor

@JakeSkinner @Kepa  this was the original method I attempted for this process, but it is not available in Enterprise 10.8.1, only in ArcGIS Online. When I attempted the ArcGIS API for Python append method, I got the error Exception('Append only available on ArcGIS Online.')ERROR:root:Append only available on ArcGIS Online.

When using the arcpy.management.Append() method, the process works if ArcGIS Pro is manually signed into at run time- it even works if ArcGIS Pro is closed out then the script is run shortly after. But this needs to be a scheduled process, and when it's run as a service after hours, it fails on the arcpy append step saying that the target feature service is unavailable or unsupported (even though a truncate step using the ArcGIS API for Python truncate successfully runs on that same service prior to that failure). 

So does this mean that both append and edit_features are unavailable options in Portal? The edit_features() method I used in the code posted above works great and is super efficient in ArcGIS Online (it consistently took about 2 minutes to append 100,000 points). I'd love to use it in Portal, too if possible...

0 Kudos