I have a workflow that ingests a feature class, loops through with an update cursor, and then appends to an SDE table. The output feature order does not match the input order. I suspect parallel batching may be happening, but I'm curious if anyone knows how it's working under the hood.
Here's a mockup of what the output data looks like:
The cursor loops through the data and assigns an ID in sequential order. Note that initially, the assigned IDs match the ObjectID. However, after a certain point it switches to alternating between a later ID number and the original number. Sometimes, it might even double up on the "second list" of numbers e.g. Feature_ID: 1, 2, 3, 7, 4, 8, 9, 5, 10, 6
Here's the code (stripped of non-necessary info):
intermediate_fc = "memory/int_fc"
arcpy.management.CopyFeatures(in_fc, intermediate_fc)
feature_num = get_feature_num(eng, proj_code, True)
fields = ["feature_id"]
with arcpy.da.UpdateCursor(intermediate_fc, fields) as cursor:
for row in cursor:
feature_num += 1
row[0] = str(feature_num).zfill(6)
cursor.updateRow(row)
arcpy.management.Append(intermediate_fc, TARGET_FC, schema_type='NO_TEST')
-
Added the sql_clause and it unfortunately is still having the same behaviorElana– Elana2024年10月04日 15:10:41 +00:00Commented Oct 4, 2024 at 15:10
1 Answer 1
I suspect arcpy.management.Append
may be sending data in batches (or otherwise async) under the hood, and the target geodatabase is just assigning new OBJECTID
values in whatever order the new rows arrive. Since the result is still sorta sequential but not a strict pattern, I wonder if row differences (e.g., geometry vertex count) are contributing to this.
If keeping your original order were important, replacing the Append
with a SearchCursor
& InsertCursor
combo, like here , could work.
PS, I also see a similar issue is mentioned here .
Explore related questions
See similar questions with these tags.