Select to view content in your preferred language

Getting AttributeError when trying to overwrite feature layer in ArcGIS Online using API for Python

3735
9
Jump to solution
05-06-2022 04:52 PM
Arlo
by
New Contributor II

I'm trying to overwrite a hosted feature layer in AGOL using the method outlined here:

https://developers.arcgis.com/python/sample-notebooks/overwriting-feature-layers/

but when I run

data_flayer.manager.overwrite('data.csv')
 
I get
 
AttributeError: 'PropertyMap' instance has no attribute 'tables'
 
I get the same error when I try to update just the csv item that the feature layer is published from:
 
data_item.update({}, 'data.csv')
data.publish(overwrite=True)

I get the same error when I attempt to overwrite two different ways- thoughts?

1 Solution

Accepted Solutions
ConradSchaefer__DOIT_
New Contributor III

In a Jupyter Notebook, looking at the .manager.properties.layers I can see there is a table item, which you would think would be in the .manager.properties.tables instead. Anyway, if you alter the @property tables function to use self.properties.layers (like the @properties layers function)instead of self.properties.tables then you make it through the issue. BUT I exited and did not let it go further because I didn't want this to alter a production asset and take a bad turn. 

 

foragolissue.JPG

Here is a screenshot of the ESRI code altered as described above...

ConradSchaefer__DOIT__1-1661535473401.png

Thanks

View solution in original post

0 Kudos
9 Replies
DanPatterson
MVP Esteemed Contributor

data.csv isn't a featurelayer but probably a table used to create a point layer.  a csv isn't a "layer" unless it is used to make one,


... sort of retired...
0 Kudos
Arlo
by
New Contributor II

Thanks for the reply. According to the documentation and the example in this sample notebook, the overwrite function takes a local data file (csv in this case) as it's only argument. The data_flayer object that I'm attempting to overwrite is a feature layer accessed from the GIS:

data_item = gis.content.search("title: Title owner:Owner", item_type= "Feature Layer")[0]
data_flayer = FeatureLayerCollection.fromitem(data_item)
data_flayer.manager.overwrite('data.csv')
I get the same AttributeError when I try to overwrite just the csv file:
 
csv_item = gis.content.search("title:Title owner:Owner", item_type= "CSV")[0]
csv_item.update({}, 'data.csv')
csv_item.publish(overwrite=True)
 
Thanks for any additional insight!
tmichael81
New Contributor

I don't have a solution but just responding to say that I am having this issue as well.  I have a script that I wrote last year that uses the same methods that you linked in your post and the overwrite portion is now producing an error.

Code:

# Get a reference to the feature layer
pw_customers = gis.content.get(items[0].itemid)
customers_collection = arcgis.features.FeatureLayerCollection.fromitem(pw_customers)
        
# Overwrite the feature layer with the new / updated data
csv_for_upload = os.path.join(os.path.split(contact_csv)[0], featurelayer_title + ".csv")
pw_customers_collection.manager.overwrite(data_file=csv_for_upload)
print("Feature layer overwritten")

 

Error:

PYTHON ERRORS:
Traceback info:
  File "c:/Users/Administrator/Desktop/python/sf_customer_to_ago.py", line 250, in <module>
    pw_customers_collection.manager.overwrite(data_file=csv_for_upload)

Error Info:
'PropertyMap' instance has no attribute 'tables'

 

ConradSchaefer__DOIT_
New Contributor III

We too are now having an issue. Not sure when it began, our process was silently failing and log file repository only goes back a few weeks. I know that it once worked and something has changed.

We are overwriting a hosted table from a csv using the ArcGIS API for Python. Version 2.0.0 as of now

Here is our traceback with some paths obscured with XXX's and ZZZ's

Traceback (most recent call last):
File "XXXXXXX", line 305, in <module>
main()
File "XXXXXXX", line 296, in main
result = data_collection.manager.overwrite(output_csv_path) # Expects csv named same as csv_name variable
File "ZZZZZZZ\Python37\lib\site-packages\arcgis\features\managers.py", line 2326, in overwrite
for table in self.tables:
File "ZZZZZZZ\Python37\lib\site-packages\arcgis\features\managers.py", line 1514, in tables
for table in self.properties.tables:
File "ZZZZZZZ\Python37\lib\site-packages\arcgis\_impl\common\_mixins.py", line 84, in __getattr__
cls=self.__class__.__name__, name=key
AttributeError: 'PropertyMap' instance has no attribute 'tables'

 

Our code from which this error arises is below. The overwrite() step is where the failure occurs.

hosted_table_item = gis.content.get(itemid=config_parser["AGOL"]["hosted_table_item_id"])
data_collection = arcgis.features.FeatureLayerCollection.fromitem(hosted_table_item)
result = data_collection.manager.overwrite(output_csv_path)  # Expects csv named same as csv_name variable

@SusanHmel__DOIT_ 

Thanks

0 Kudos
ConradSchaefer__DOIT_
New Contributor III

Looking at it further, it seems under the hood that the "tables" key doesn't exist in the collection properties but is expected to be there. 

ConradSchaefer__DOIT__0-1661534405546.png

However, for the property just above for layers, the self.properties does have a 'layers' key.

Here is the print out from the keys() call. You will see "layers" as the last key but there is no "tables" key. I think that is either the AGOL side missing a "tables" key or the code not accomodating/adding it?? 

dict_keys(['adminServiceInfo', 'enforceFieldVisibility', 'currentVersion', 'serviceItemId', 'serviceDescription', 'hasVersionedData', 'supportsDisconnectedEditing', 'hasStaticData', 'hasSharedDomains', 'maxRecordCount', 'supportedQueryFormats', 'supportsVCSProjection', 'supportedExportFormats', 'capabilities', 'description', 'copyrightText', 'initialExtent', 'fullExtent', 'allowGeometryUpdates', 'units', 'supportsAppend', 'supportsSharedDomains', 'supportsWebHooks', 'supportsTemporalLayers', 'layerOverridesEnabled', 'size', 'syncEnabled', 'supportsApplyEditsWithGlobalIds', 'supportsReturnDeleteResults', 'supportsLayerOverrides', 'supportsTilesAndBasicQueriesMode', 'supportsQueryContingentValues', 'supportedContingentValuesFormats', 'supportsContingentValuesJson', 'advancedEditingCapabilities', 'editorTrackingInfo', 'xssPreventionInfo', 'layers'])

 @SusanHmel__DOIT_ 

0 Kudos
ConradSchaefer__DOIT_
New Contributor III

In a Jupyter Notebook, looking at the .manager.properties.layers I can see there is a table item, which you would think would be in the .manager.properties.tables instead. Anyway, if you alter the @property tables function to use self.properties.layers (like the @properties layers function)instead of self.properties.tables then you make it through the issue. BUT I exited and did not let it go further because I didn't want this to alter a production asset and take a bad turn. 

 

foragolissue.JPG

Here is a screenshot of the ESRI code altered as described above...

ConradSchaefer__DOIT__1-1661535473401.png

Thanks

0 Kudos
cpatton_geojobe
New Contributor

Hi,

Me and @tmichael81 had this issue initially and something I put together at the time before 2.0.1 was released was the following:

You can ignore lines 1-12. I only included them to show how the data was structured. I also spent time digging in the arcgis api for python module and it seemed empty handed at the time.

The code below recreates the overwrite by just simple breaking off the rows to be appended by chunks depending on the size of your data using  the numpy module(Line 15). Then, deleting the features on the layer(this can done on a collection by iterating through the multiple layers) and truncating the table to reset everything(Line 23-24). I use edit_features here(Line 26), and you could argue that append would be more appropriate. 

 

                # If latitude and longitude are avaliable then make the geometry point for the feature
                if(x and y):
                    geometryPoint = Point({"x": x, "y": y, "spatialReference" : {"wkid" : 4326}}) # Create Geometry
                if(geometryPoint):
                    rows.append(Feature(attributes=newRow, geometry=geometryPoint))
                else:
                    rows.append(Feature(attributes=newRow))

                # Reset geometry variables
                x = None
                y = None
                geometryPoint = None

        # Break the rows into chunks so they can be uploaded to AGOL without issues.
        dataSets = np.array_split(rows, round(len(rows) / 100))

        # Get a reference to the feature layer
        customers = gis.content.get(items[0].itemid)
        customers_fl = pathwise_customers.layers[0]
        # customers_collection = arcgis.features.FeatureLayerCollection.fromitem(customers)
        
        # Overwrite the feature layer with the new / updated data
        customers_fl.delete_features(where="objectid > 0")
        customers_fl.manager.truncate()
        for dataSet in dataSets:
            customers_fl.edit_features(adds=dataSet[0:dataSet.size], rollback_on_failure=False)

        # customers_collection.manager.overwrite(data_file=csv_for_upload)
        print("Feature layer overwritten")

 

However, supposedly ArcGIS API for Python 2.0.1 module fixes this:

https://developers.arcgis.com/python/guide/release-notes-201/

  • FeatureLayerCollectionManager
  • Fixes BUG-000146997 where overwrite() fails with AttributeError: 'PropertyMap' instance has no attribute 'Tables'
ConradSchaefer__DOIT_
New Contributor III

@cpatton_geojobe 

Thanks for that workaround idea and the note on the new release solving this issue. 

0 Kudos
Arlo
by
New Contributor II

This is what worked for me using Version 2.0.0, but I ended up just reverting back to 1.9.1 for a cleaner fix. Upgrading to 2.0.1, of course, is the best solution now.

0 Kudos