On Pro 3.3.2. Hello, I've been using custom python tools to standardize data for a few years. Recently, the Merge rule seems to be ignoring the input FieldMappings object. Print statements indicate the field maps are being created properly, there are no issues in schema (these are fixed in script)... Please let me know if you notice anything I'm missing or have wrong in the following snippet. Thanks.
printMessage(f"Creating FieldMappings for {fmaps_flag} fields")
f_Mappings = arcpy.FieldMappings()
f_Mappings.addTable(st_class)
wait_flag = False
for s_field, param in c_dict.items():
#Skip if waiting for paired field
if wait_flag:
param = c_dict[s_field[:-1] + 'L']
wait_flag = False
#Check if L field has a matching R field
elif s_field[-1:] == 'L' and param and not c_dict[s_field[:-1] + 'R']:
wait_flag = True
if param:
field_map_index = f_Mappings.findFieldMapIndex(s_field)
fieldMap = f_Mappings.getFieldMap(field_map_index)
fieldMap.addInputField(rc, param)
fieldMap.mergeRule = 'First'
f_Mappings.replaceFieldMap(field_map_index, fieldMap)
arcpy.AddMessage(f"{param:<18}---> {s_field}")
for fmap in f_Mappings.fieldMappings:
outp = fmap.outputField.name
if c_dict[str(outp)]: arcpy.AddMessage(f"{outp} input field: {fmap.getInputFieldName(fmap.findInputFieldIndex(rc, c_dict[str(outp)]))}")
printMessage("Preparing Data for Merge")
#Pre-merge calculations for non-Douglas counties
inpt = [st_class, rc]
if fmaps_flag:
#Douglas is submitting files that do not allow null values
if "Douglas" not in county:
arcpy.AddMessage("Calculating Fields (Pre-merge)...")
calcFields(rc, c_dict, False)
arcpy.AddMessage("Merging data...")
arcpy.management.Merge(inpt, merge_path, field_mappings=f_Mappings)
else:
arcpy.AddMessage("WARNING: No FieldMappings...")
arcpy.AddMessage("Merging data without field mappings...")
arcpy.Merge_management([st_class, rc], merge_path)
arcpy.AddMessage("Merge Complete!")