Select to view content in your preferred language

Attribute rule error on python updatecursor

1418
4
Jump to solution
12-13-2021 01:47 PM
JimmyBowden
Frequent Contributor

In ArcGIS Pro 2.8.3 when trying to update a feature using Python update cursor an error occurs (see below).  This error occurs in our enterprise implementation of the Water Utility Network Solution and also when using the sample Naperville data provided in a file geodatabase.  Editing workflows in the ArcGIS Pro UI work fine for this type of edit.  These attribute rules were provided as part of the Water Utility Network Solution. If I disable the attribute rule it will fail on another rule (Water Line - MeasuredLength From Shape), when both are disabled the edit occurs without error.  Here is a simplified snippet of code:

 

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
idFeature = []

for lyr in m.listLayers():
    lyrdesc = arcpy.Describe(lyr)
    if lyr.isFeatureLayer:
        fi = lyrdesc.fieldInfo
        obj = lyrdesc.FIDSet
        if obj:              
            wc =  "OBJECTID in ({0})".format(obj.replace(";",","))
            print(wc)
            with arcpy.da.UpdateCursor(lyr, ["OID@", "NOTES"],wc) as cursor:
                for row in cursor:
                    row[1] = "TEST"
                    cursor.updateRow(row)

 

RuntimeError: Failed to evaluate Arcade expression. [
Rule name: Water Line - Cathodic Protection Traceability,
Triggering event: Update,
Class name: WaterLine,
GlobalID: ,
Arcade error: Field not found cptraceability,
Script line: 25]

 

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

This is happening because the AR tried to use a field that was not fetched by python.

 

Two solutions,

you can wrap the python call with arcpy.da.Editor(str(workspacepath)) which will give the editor context. 

or you can include all the fields that the AR require in the UpdateCursor call (cptraceability) in this case. 

 

View solution in original post

4 Replies
HusseinNasser2
Esri Contributor

This is happening because the AR tried to use a field that was not fetched by python.

 

Two solutions,

you can wrap the python call with arcpy.da.Editor(str(workspacepath)) which will give the editor context. 

or you can include all the fields that the AR require in the UpdateCursor call (cptraceability) in this case. 

 

VinceE
by
Frequent Contributor

Is there a means of programmatically (ArcPy) getting a list of all fields that are involved in Attribute Rule Calculations? It appears that it is possible to use arcpy.da.Describe with the ['attributeRules'] key to obtain the names of the fields that have calculations applied, but that will not include fields that might be part of the calculation. For example, you can get the name of Field3 where the calculation is applied, but I don't see a means of getting the names of Field1 and Field2 that are used to calculate a sum, for example, to be populated in Field3.

0 Kudos
JoeBorgione
MVP Emeritus

Or turn the rule off when you are running the update cursor....

That should just about do it....
0 Kudos
geopamplona
Emerging Contributor

@HusseinNasser2 

in my case I am doing same edit against a feature service

it seems as if from arcpy it is indicated to do edits against database, and not against services

to make edits against a feature service I should use arcpy or arcgis for python. How could I get the same result using ArcGIS API for Python?

0 Kudos