AnsweredAssumed Answered

Append tool crashing in ArcPy if arcpy.env.preserveGlobalIds = True?

Question asked by david12385 on Nov 9, 2019
Latest reply on Nov 12, 2019 by david12385

So I've written a Python script called driver.py (using Python environment from Pro 2.4.2) that will append several SDE databases' feature classes to a coalesced database. All databases have matching schema. My goal is to preserve Global IDs on all output. The script performs several tasks:
1) It creates an empty file geodatabase.

2) The necessary feature classes from the first SDE database are exported to the output file GDB (with arcpy.FeatureClassToFeatureClass_conversion).

3) The remaining SDE database feature classes are then appended to the exports from the first SDE's feature classes.

 

Here's the script:

 

import arcpy
import os

sde_folder = "My\\SDE\\Folder\\Path"

output_folder = "My\\Output\\Folder\\Path"

gdb_name = "testing_gdb.gdb"

schemaType = "TEST" #"NO_TEST"
fieldMappings = ""
subType = ""

if arcpy.Exists(output_folder + gdb_name):

    print("GDB already exists")

else:

    arcpy.CreateFileGDB_management(output_folder, gdb_name)

arcpy.env.workspace = sde_folder

folder_Connections_SDE = arcpy.ListWorkspaces("*", "SDE")

# For each GDB in the workspace connections folder...
for sdeDatabase in folder_Connections_SDE:

    arcpy.env.workspace = sdeDatabase
    arcpy.env.preserveGlobalIds = True

    if sdeDatabase == folder_Connections_SDE[0]:

        print("First SDE database")
        fc_list = arcpy.ListFeatureClasses()

        for fc in fc_list:

            if "QC_REPORTS" in fc:

                print("Skipped:" + fc)
                pass

            elif "REPLICATION_BND" in fc:

                print("Skipped:" + fc)
                pass

            else:

                output_name = fc.rsplit(".")[2]
                print(output_name)
                arcpy.env.overwriteOutput = True
                arcpy.FeatureClassToFeatureClass_conversion(fc, output_folder + gdb_name, output_name)

    else:

        print(sdeDatabase)

        fc_list = arcpy.ListFeatureClasses()

        for fc in fc_list:

            if "QC_REPORTS" in fc:

                print("Skipped:" + fc)
                pass

            elif "REPLICATION_BND" in fc:

                print("Skipped:" + fc)
                pass

            else:

                output_name = fc.rsplit(".")[2]

                input_feature_class_path = os.path.join(sdeDatabase, fc)
                output_feature_class_path = os.path.join(output_folder + gdb_name, output_name)

                arcpy.Append_management(input_feature_class_path, output_feature_class_path, schemaType, fieldMappings, subType)

 

If I run the above script with...

arcpy.env.preserveGlobalIds = False

...the script executes without error and all output is created, but the Global IDs are not preserved.

 

However, if I change that boolean to True, the script successfully creates the output GDB and successfully completes the Feature Class to Feature Class conversion (while also preserving the Global IDs), but it fails during the Append operation with the following error:

 

Traceback (most recent call last):
  File "My/Script/Folder/Path/driver.py", line 81, in <module>
    arcpy.Append_management(input_feature_class_path, output_feature_class_path, schemaType, fieldMappings, subType)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4929, in Append
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4926, in Append
    retval = convertArcObjectToPythonObject(gp.Append_management(*gp_fixargs((inputs, target, schema_type, field_mapping, subtype, expression), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (Append).

 

I read this from Esri on the preserveGlobalIds help page:

"For the Append tool, this environment only applies to enterprise geodatabase data and will only work on data that has a Global ID field with a unique index. If the Global ID field does not have a unique index, the tool may fail."

 

Since I'm utilizing enterprise geodatabases for the append, I'm unsure about the unique index issue. Does anybody know if I'm missing something here? Thanks for any clarification!

Outcomes