I'm trying to populate a field based on the values of another field. CalculateField was buggy, so I switched to da.UpdateCursor. This initially worked when I ran it as part of a script tool on ArcGIS Pro 2.4.3, but when I returned to this project after putting it aside for a few weeks and then making a few minor modifications to my code, ArcGIS Pro gave me an error:
Traceback (most recent call last): File "Y:\AGUSPDB\States Procedures\Normalizer.py", line 126, in <module> for value in APN_Update: RuntimeError: An invalid SQL statement was used. [SELECT APN, Y:\AGUSPDB\03 States Compiled\Compiled_Ashley_AR_20_Parcels.gdb\Ashley_AR_Parcels, OBJECTID, Shape_Area, Shape_Length FROM Ashley_AR_Parcels] Failed to execute (Normalizer).
Incidentally, this code works in the Python IDLE shell, so I suspect the issue may have something to do with ArcGIS Pro. The offending code is prefaced with the comment "Problem begins here". Because the feature class's file path and other fields I never coded somehow ended up in the UpdateCursor SQL statement, I've added the a few other steps for context.
import arcpy #Joins a standardized feature class template to the feature class the user loads. FC_toNormalize = arcpy.SpatialJoin_analysis(inFeatures, normalizedTemplate, filepath,\ "JOIN_ONE_TO_ONE", "KEEP_ALL", "#", "HAVE_THEIR_CENTER_IN") #Create list of fields to reverse-index from the template's attribute table fields = [f.name for f in arcpy.ListFields(FC_toNormalize)] #Problem begins here. fields[-13] is called "APN". with arcpy.da.UpdateCursor(FC_toNormalize, [str(fields[-13]), "userSelected_field"]) as APN_Update: for value in APN_Update: value = value APN_Update.updateRow(value)
As for the minor modifications I made to my code before re-running the tool, they shouldn't have caused problems, but here they are:
- Renamed a few variables
- Reorganized the placement of some GetParameterAsText functions within the code (but not the index positions)
- Added a new function a few lines below the for loop in which this error occurs
Even though the code works in the Python shell, I'll obviously have to modify it so ArcGIS Pro to digest it. Any thoughts?