Select to view content in your preferred language

.edit_features() says it succeeds, but doesn't actually update features

702
1
08-23-2023 02:11 PM
NickNuebel
New Contributor II

I'm trying to run a notebook script in AGOL that checks and fixes features with null geometry. The results from edit_features( ) operation indicates success, but the updates never appear in the feature layer. Any idea why this might be? 

For parent features with null geometry, the script loops through related child features, unions their geometry, and replaces parent features' geometry with the unioned product. 

from arcgis.gis import GIS
import arcgis 
gis = GIS("home")

uas_fs_id = '09379d41ab3448549525914a4b08524a'
uas_fs = gis.content.get(uas_fs_id)

missions_layer = uas_fs.layers[0]
flights_layer = uas_fs.layers[1]

missions = missions_layer.query()

for mission in missions:
    if mission.geometry is None:
        mission_globalid= mission.get_value('globalid')
        
        flights = flights_layer.query(where="parentglobalid='{}'".format(mission_globalid))
        
        flights_geom = [flight.geometry for flight in flights]
        
        unioned = arcgis.geometry.functions.union(spatial_ref={'wkid': 4326, 'latestWkid': 4326}, geometries=flights_geom, gis=gis)
        
        mission.geometry = unioned
        
        result = missions_layer.edit_features(updates=[mission])
        
        print(result)

 

results:

{'addResults': [], 'updateResults': [{'objectId': 1, 'uniqueId': 1, 'globalId': 'bcb70fa1-b009-4133-8f33-1a4d707274fe', 'success': True}], 'deleteResults': []}
{'addResults': [], 'updateResults': [{'objectId': 2, 'uniqueId': 2, 'globalId': 'd5067b60-7f2c-4ef8-8f6a-1c0afa9fae55', 'success': True}], 'deleteResults': []}
{'addResults': [], 'updateResults': [{'objectId': 3, 'uniqueId': 3, 'globalId': '260083d3-0834-4f31-81e5-fb7fca7d4aa7', 'success': True}], 'deleteResults': []}

 

It always says it succeeds, but never does anything. What gives? 

 

1 Reply
EarlMedina
Esri Regular Contributor

I've seen this before - the error handling is not always the best. What I have done in the past to troubleshoot is run small batches through edit_features until I can find the culprit(s). I can't recall the specifics of what was wrong each time, but I'm pretty sure at least once it was that a float was being applied to an int field. I think other times they were strings that exceeded the max length. You say you're updating geometry - I don't believe I've encountered an issue with that yet, but if the update includes non-geometry fields then perhaps you can check the below:

For the first scenario, you may need to check your dtypes to ensure that they're compatible.

For the second scenario (which happened a lot more frequently), I used to have a helper function that found the max string length in a dataframe column and compared that to the field length of the Feature Layer field. If it exceeded the field length, then I would update the feature layer definition to increase the field length. If this isn't an option, you might be able to pare down the string causing the issue.