Cannot delete features in hosted feature layer using ArcGIS API for Python

1754
4
05-07-2021 11:01 AM
Thomas_Z1
New Contributor III

Hi there,

I have a hosted Feature Layer on AGOL with 3 layers.

When I run following code:

 

 

gis = GIS("portal", "user", "password")
feature_layer_item = gis.content.get("layer item id")

for layer_id in [0, 1, 2]:
    layer = feature_layer_item.layers[layer_id]
    result = layer.delete_features(where="1=1")
    logging.info("Delete Result: {}".format(result))

# note: code snippet simplified for question

 

 

The data is deleted for 2 layers but not the third one, even though it's the same code and a simple where clause.

I get following error which does not help at all:

 

 

Delete Result: {'deleteResults': [{'objectId': 1, 'uniqueId': 1, 'globalId': None, 'success': False, 'error': {'code': 1000, 'description': "Incorrect syntax near ')'."}}]}
Incorrect syntax near ')'

 

 

I do not see an error in the where clause 1=1 and it works for the other layers.

There must be something I miss or could this be a bug?

0 Kudos
4 Replies
DB_PPF
by
New Contributor II

Can you print anything about the layer when you're processing the 3rd layer?  Or the raw unformatted result.   Seems like it's coming back null.

0 Kudos
Thomas_Z1
New Contributor III

I am able to print a JSON string with

 

print(layer.properties)

 

(unfortunately I cannot post the whole string, there are confidential information, if you know a specific part which should be checked, let me know)

However, the layer is not null. And it's actually the second of three layers. No exception thrown or other errors.

 

Result of

 

layer.delete_features(where="1=1")

 

is

 

{'deleteResults': [{'objectId': 1, 'uniqueId': 1, 'globalId': None, 'success': False, 'error': {'code': 1000, 'description': "Incorrect syntax near ')'."}}]}

 

It's just not making sense.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Since you are deleting all features, I would recommend using the truncate method.  This is much faster.  Ex:

hostedFS= gis.content.get(fsItemId)
fLyr = hostedFS.layers[0]
fLyr.manager.truncate()

 

0 Kudos
Thomas_Z1
New Contributor III

Thank you.

The script above is actually a simplified minimum (non) working example. The issue occurs with this very simple where clause (1=1) and with my actual where clause (fieldName='fieldText').

I am implementing a unit test for an ArcGIS for Python script. I was hoping that I don't have to delete all features so I could run tests asynchronously. But your suggestion could work as a workaround.

It is very strange, why it does work for two of the layers (which have - by the way - exactly the same fields and settings) but not for the third one.

0 Kudos