Bug: CalculateField errors after AlterField Tool

1502
11
Jump to solution
01-09-2017 01:12 PM
ShaneBuscher
Occasional Contributor

There looks to be a bug with running the CalculateField tool directly after the AlterField tool via arcpy. AlterField runs successful, but as shown in red below, CalculateField fails with a 'column not found' error. The column listed in the error is not what was altered, it always happens to be the first column in the feature class. 

The environment is ArcGIS 10.3.1, 64-bit Python, ArcSDE 10.3.1 on SQL Server 2008. For security\privacy I replaced the arguments in the script. You can substitute your own SDE data to get the same result. 

# Script

import arcpy

arcpy.env.workspace = "../some_sde_connection.sde"

arcpy.AlterField_management("InputFeatureClass", "OriginalFieldName", "NewFieldName", "NewFieldName")

arcpy.CalculateField_management("InputFeatureClass", "AnotherField", "Foo", "PYTHON_9.3")

C:\projects\>alter_table_bug.py
Traceback (most recent call last):
File "C:\projects\OPS_Int_ArcGIS\source\scripts\alter_table_bug.py", line 15, in <module>
"PYTHON_9.3")
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 3457, in CalculateField
raise e
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Attribute column not found [42S22:[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'TheFirstColumnInTheTable'.] [Database.SchemaName.InputFeatureClass][STATE_ID = 0]
Failed to execute (CalculateField).

0 Kudos
11 Replies
JoshuaBixby
MVP Esteemed Contributor

I don't think the exception is necessarily vague.  It is saying you have a syntax error with CalculateField, likely from the expression.  Can you provide any more details about your expression or call to CalculateField?

0 Kudos
ShaneBuscher
Occasional Contributor

The expression syntax is in my original post, and works fine when not performing an AlterField beforehand.

0 Kudos