laptop and a wrench

漏洞

Arcpy.Append_management does not append global ID records from the input dataset to the target data in the GUID field in ArcGIS Pro 3.1.

上次发布: March 22, 2023 ArcGIS Pro
漏洞 ID 编号 BUG-000156786
已提交March 21, 2023
上次修改时间April 29, 2025
适用范围ArcGIS Pro
找到的版本3.1
操作系统Windows OS
操作系统版本N/A
修正版本3.3
状态As Designed

附加信息

This a known limitation that is the result of changes to the fieldMappings object in ArcGIS Pro 3.1 that attempts to honor users' edits of the field map in any field map related tool, whether those edits are done in the UI, ModelBuilder, or python script. For this case with the Append tool, the output table schema must be based on the schema of the target dataset. However, the provided script adds the source layer into the fieldMapping object first. Because an edited target schema is provided, the Append tool detects a wrong output schema and reset to the default target schema, voiding any user editing (in this case the customized mapping of GlobalID to GlobalIDCopy).The script provided in the workaround section of this BUG is the recommended way to script the Append tool UI behavior. However, based on the provided script in this issue, it is also sufficient to add the line fieldMappings.addTable(fc) before fieldMappings.addTable(layer). This results in the desired field mappings from the sample script. This results in the following script: ```python# Esri start of added importsimport sys, os, arcpy# Esri end of added imports# Esri start of added variablesg_ESRI_variable_1 = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_source')g_ESRI_variable_2 = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_destination')# Esri end of added variablesimport arcpy# Create FieldMappings object to manage merge output fields this is so that we can retain the original globalID valuefieldMappings = arcpy.FieldMappings()layer = g_ESRI_variable_1fc = g_ESRI_variable_2### Add the fieldMapping of the target dataset to the fieldMappings object ### before the input datasetfieldMappings.addTable(fc)###fieldMappings.addTable(layer)fldMap_GID = arcpy.FieldMap()fldMap_GID.addInputField(layer,"GlobalID")GIDName = fldMap_GID.outputFieldGIDName.name = "GUIDCopy"GIDName.type = "GUID"fldMap_GID.outputField = GIDNamefieldMappings.addFieldMap(fldMap_GID)arcpy.Append_management(layer,fc,"NO_TEST",fieldMappings)```

解决办法

In the user-provided code sample to reproduce the issue, the fieldsMappings.addTable(layer) object is creating the field mapping with all of the input fields, which is backwards; the target feature class table must first be added to the fieldMappings object before the input, so that the input fields automatically matches to the field names from the target when the names are the same. This matches the Append tool behavior in the Geoprocessing pane, where the field map loads all of the fields from the target, and users can map source fields from the input to those target fields. The code below works for the reproduced case provided for ArcGIS Pro 3.1:

## Start sample code
import sys, os, arcpy

input = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_source')
target = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_destination')

fieldMappings = arcpy.FieldMappings() 
# Add all fields from target layer
fieldMappings.addTable(target) 
# Add all fields from input layer, which will automatically match to field names from the target when the names are the same
fieldMappings.addTable(input)
arcpy.AddMessage(f"initial fieldmap = {fieldMappings.exportToString()}") 

# Loop through all fields in the field map, and clean out the input fields from the target, so each field map only has an input from the input layer, which matches the behavior of the Append tool UI
for fmi in range(fieldMappings.fieldCount): 
    fm = fieldMappings.getFieldMap(fmi) 
    for targetfield_index in range(fm.inputFieldCount): 
        intable = fm.getInputTableName(targetfield_index) 
        if intable == arcpy.Describe(target).catalogPath: 
            fm.removeInputField(targetfield_index) 
            fieldMappings.replaceFieldMap(fmi, fm)
            break
        
# find the existing guid field in the target layer
guid_field_index = fieldMappings.findFieldMapIndex("GUIDCopy")
guid_fieldmap = fieldMappings.getFieldMap(guid_field_index)
# add the input globalID field to the guid fieldmap
guid_fieldmap.addInputField(input, "GlobalID")
fieldMappings.replaceFieldMap(guid_field_index, guid_fieldmap)
arcpy.AddMessage(f"final fieldmap = {fieldMappings.exportToString()}") 
arcpy.Append_management(input, target, "NO_TEST", fieldMappings)

## End sample code

重现步骤

漏洞 ID: BUG-000156786

软件:

  • ArcGIS Pro

当漏洞状态发生变化时获得通知

下载 Esri 支持应用程序

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项