Unable to update hosted feature layer with edit_features and a pandas dataframe

207
2
a month ago
michael_vetter
Occasional Contributor

I recently upgraded my ArcGIS Pro from version 2.9 to 3.1 and with this upgrade the ArcGIS API for Python version upgraded from 1.9.1 to 2.1.0.2. I have a script that reads an Excel file into a Pandas dataframe to update existing data in a hosted feature layer. I do some calculations within the dataframe then use edit_features(updates=) to update the hosted feature layer. This used to work, but since I've upgraded I'm getting an error message saying "The specified feature could not be updated or does not exist". I'm the owner of the hosted feature layer so I have full editing capabilities on it. Any help is appreciated!

Here's my code:

import pandas as pd
from arcgis.gis import GIS
gis = GIS("home")

# Hosted feature layer
dest = gis.content.get("itemID")
dlayer = dest.layers[0]

# Query the layer for open records and return needed fields
containerProblemLayer = dlayer.query(
    where="StateCode = '0'",
    out_fields=["CaseNumber","ResolutionNotes"]
).sdf

# Read Excel file
cpDynamics = pd.read_excel("path to excel")

# Format the case numbers so a join can occur
try:
    cpDynamics["Case Number (Parent Case) (Case)"] = cpDynamics.loc[cpDynamics["Case Number (Parent Case) (Case)"].str.contains("-"), ["Case Number (Parent Case) (Case)"]] = cpDynamics["Case Number (Parent Case) (Case)"].str[-10:]
    cpDynamics["Case Number (Parent Case) (Case)"] = cpDynamics["Case Number (Parent Case) (Case)"].astype("int64")
except:
    cpDynamics["Case Number (Parent Case) (Case)"] = cpDynamics["Case Number (Parent Case) (Case)"].astype("int64")

try:
    containerProblemLayer["CaseNumber"] = containerProblemLayer.loc[containerProblemLayer["CaseNumber"].str.contains("-"), ["CaseNumber"]] = containerProblemLayer["CaseNumber"].str[-10:]
    containerProblemLayer["CaseNumber"] = containerProblemLayer.astype("int64")
except:
   containerProblemLayer["CaseNumber"]=containerProblemLayer["CaseNumber"].astype("int64")

# Create a join
inner = containerProblemLayer.merge(cpDynamics, how="inner", left_on="CaseNumber", right_on="Case Number (Parent Case) (Case)")

# Calculate ResolutionNotes field
inner["ResolutionNotes"] = inner["Container Damage:"]+" "+inner["Additional Information (Parent Case) (Case)"]

finalTable = inner.drop(["(Do Not Modify) Container Problem","(Do Not Modify) Row Checksum","(Do Not Modify) Modified On","Case Number (Parent Case) (Case)","Created On","Container Damage:","Additional Information (Parent Case) (Case)","Status (Parent Case) (Case)"],axis=1)

# Create a feature set to use for the update
features_set = finalTable.spatial.to_featureset()

# Update the hosted layer
dlayer.edit_features(updates=features_set)

 

Here's the error message:

michael_vetter_0-1713540576889.png

 

0 Kudos
2 Replies
EarlMedina
Esri Regular Contributor

Any chance that layer has globalids? If so, you try to set the  "use_global_ids" parameter of edit_features to True.  Only other thought is maybe there's a problem with the auth.

0 Kudos
michael_vetter
Occasional Contributor

No the layer doesn't have globalids

0 Kudos