laptop and a wrench

Erro

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.

Última Publicação: March 22, 2023 ArcGIS Pro
Número de ID do Erro BUG-000156786
EnviadoMarch 21, 2023
Última ModificaçãoApril 29, 2025
Aplica-se àArcGIS Pro
Versão encontrada3.1
Sistema OperacionalWindows OS
Versão do Sistema OperacionalN/A
Versão Fixa3.3
StatusAs Designed

Informações Adicionais

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)```

Solução Provisória

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

Etapas para Reproduzir

ID do Erro: BUG-000156786

Software:

  • ArcGIS Pro

Seja notificado quando o status de um erro mudar

Baixe o Aplicativo de Suporte da Esri

Descubra mais sobre este tema

Obtenha ajuda de especialistas do ArcGIS

Entre em contato com Suporte Técnico

Baixe o Aplicativo de Suporte da Esri

Ir para as opções de download