Select to view content in your preferred language

edit_features Succeeds but doesn't add some attributes

313
4
10-23-2024 09:23 PM
nate0102
Occasional Contributor

Hello,

Issue summary: feature_table.edit_features(add=[...]) adds correct number of records but ONLY attributes for single column come through to the hosted feature table. Everything else other than scientificName is blank. My fields are mapped correctly from python dictionary to Hosted Table.

 

With Python, I am trying to update all records in two AGO Hosted Tables using "feature_table.edit_features(adds=)".

My process is:

  1. delete all features - feature_table.delete_features(where="1=1")
  2. get the data prepared - list of dictionaries as below example

 

[{'attributes': {'lga': 'test',
   'scientificName': 'Acacia longifolia',
   'classificationLocal': 'Very High Priority',
   'localScientific': 'Acacia longifolia'}},
 {'attributes': {'lga': 'test',
   'scientificName': 'Amaryllis belladonna',
   'classificationLocal': 'High Priority',
   'localScientific': 'Amaryllis belladonna'}}]

 

  • Add the list to the Hosted table
    I get all success, no errors.

 

{'addResults': [{'objectId': 1016,
   'uniqueId': 1016,
   'globalId': '2E655834-2E92-4A57-8F8B-2697122C1DE6',
   'success': True},
  {'objectId': 1017,
   'uniqueId': 1017,
   'globalId': 'F09D7D37-98A9-4364-9D9F-35CC8151FA9E',
   'success': True}],
 'updateResults': [],
 'deleteResults': []}​

 

  • ISSUE: only Scientific name data comes through... other fields are blank.
    This same issue happens on two tables i.e. scientific name comes through, everything else blank. It doesn't matter if I do all records or just a subset (two in the examples below).
    nate0102_0-1729743623897.png

     

Extra info... Hosted Table fields:

{'OBJECTID': 0, 'scientificName': 1, 'lga': 2, 'classificationLocal': 3, 'localScientific': 4, 'GlobalID': 5}
{'OBJECTID': 0, 'scientificName': 1, 'lga': 2, 'classificationLocal': 3, 'localScientific': 4, 'GlobalID': 5}
{'OBJECTID': 0, 'scientificName': 1, 'commonName': 2, 'wons': 3, 'waStateDeclared': 4, 'qldStateDeclared': 5, 'nswStateDeclared': 6, 'vicStateDeclared': 7, 'saStateDeclared': 8, 'ntStateDeclared': 9, 'GlobalID': 10}

 

any ideas? I can't figure out what is going wrong here.

Thanks,

Nathan

 

Tags (1)
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @nate0102,

Could you post your code?  Below is an example I was able to get to work:

from arcgis.gis import GIS

# Variables
username = 'jskinner_rats'
password = '********'
itemID = '5b86f23053fc40aebb7197ce735a4dfc'

# Connect to portal
print("Connecting to AGOL")
gis = GIS("https://www.arcgis.com", username, password)

# Reference Table
print("Referencing table")
fLayer = gis.content.get(itemID)
editTable = fLayer.tables[0]

addFeatures = [
    {
        'attributes': {
            'lga': 'test',
            'scientificName': 'Acacia longifolia',
            'classificationLocal': 'Very High Priority',
            'localScientific': 'Acacia longifolia'
        }
    },
    {
        'attributes': {
            'lga': 'test',
            'scientificName': 'Amaryllis belladonna',
            'classificationLocal': 'High Priority',
            'localScientific': 'Amaryllis belladonna'
        }
    }
]

# Add record
print("Adding records")
for record in addFeatures:
    editTable.edit_features(adds=[record])
    print(result)
print('Finished')

 

0 Kudos
nate0102
Occasional Contributor

Hi @JakeSkinner, thank you for your response. 

I first read in my data from SQL db as a Pandas Dataframe:

nate0102_0-1730754001261.png

Then iterate through the rows to create the list of dictionaries (the edits). 

# Prepare the data to be added to the lookup table by iterating through dataframe rows
lookup_lga_class_data = []
for index, row in df_arcade_lookup_lga_class.iterrows():
    lookup_lga_class_data.append({
        "attributes": {
            "lga": row["lga"],
            "scientificName": row["scientific_name"],
            "classificationLocal": row["classification_local"],
            "localScientific": row["local_scientific"]
            }
        })

lookup_pwd_data = []
for index, row in df_arcade_lookup_pwd.iterrows():
    lookup_pwd_data.append({
        "attributes": {
            "commonName": row["common_name"],
            "scientificName": row["scientific_name"],
            "wons": row["wons"],
            "waStateDeclared": row["wa_state_declared"],
            'qldStateDeclared': None,
            'nswStateDeclared': None,
            'vicStateDeclared': None
            }
        })

# test to make sure dictionary has populated correctly (it does).
lookup_lga_class_data[:2]
lookup_pwd_data[:2]

# delete the existing features
ft_lookup_lga_class.delete_features(where="1=1")

# add the edits
ft_lookup_pwd.edit_features(adds=lookup_pwd_data)
ft_lookup_lga_class.edit_features(adds=lookup_lga_class_data)

The main difference I can see between our code is that I edit_features in one line by adding the whole list in, instead of a for loop.

Thanks again for your time.

Nathan

0 Kudos
BijanTaheri
Occasional Contributor

Can you post the field overview? Maybe your fields aren't configured as String or they have domains on them?

0 Kudos
nate0102
Occasional Contributor

Hello @BijanTaheri thank you for your response. Please see below images.

All strings, no domain.

 

nate0102_0-1730694456637.png

 

nate0102_1-1730694473350.png

nate0102_2-1730694493674.png

 

 

0 Kudos