I created a geoprocessing tool using arcpy/python to insert a row to a table that is versioned. the code works but the inserted row just did not show up in the attribute window under the Edit tab or in the attribute table. My ESRI contact told me to click Refresh at the content pane under "List by Data Source". I think it worked for a while. I started to test the tool again. the Refresh button stopped working. the tools ran without any error and just did not see the new rows. I clicked Reconcile option at the Manage Version window and suddenly all the inserted rows showed up. Wonder what is wrong with my script. Please help. Thanks!
Software: ArcGIS Pro 2.9
Database: Oracle and versioned
Below is the part of code which does the inserting:
inspection_id="12-23-2022"
edit = arcpy.da.Editor(workspace_sde)
edit.startEditing(False, True)
# compose row to be inserted into tv asset table
flds_tv=[]
flds_tv.insert(0,"DRAINAGE_ID")
flds_tv.insert(1,"INSPECTION_ID")
new_records=[]
index=0
with arcpy.da.SearchCursor(drainage_pipe_layer, ["DRAINAGE_ID"]) as cur:
for row in cur:
drainage_id=row[0]
arcpy.AddMessage ("drainageid=="+str(drainage_id) +" inspectionid=="+inspection_id)
print ("table drainageid=="+str(drainage_id))
newrow=[drainage_id, inspection_id]
new_records.insert(index, newrow)
index=index+1
# insert values into tv asset table
edit.startOperation()
if (len(new_records)>0):
arcpy.AddMessage ("before insert cursor tv asset path=="+tv_asset_path)
with arcpy.da.InsertCursor(tv_asset_path, flds_tv) as icur: # get "cannot update table " error
for row in new_records:
arcpy.AddMessage ("inside insert cursor tv asset path=="+tv_asset_path)
icur.insertRow(row)
edit.stopOperation()
edit.stopEditing(True)
Solved! Go to Solution.
Yes. I found out my problem. The connection file pointed to the default version. The layers in the map are in my understanding. Somehow my python code inserted rows to the default version; that is why I have to reconcile them to see them.
Now I need to make sure my inserts go to my version.
Thank you all for the help.
You can add the reconcile to the script, after the edit session closes.
Is your script connecting to SDE connected to the DEFAULT version?
R_
Yes. I found out my problem. The connection file pointed to the default version. The layers in the map are in my understanding. Somehow my python code inserted rows to the default version; that is why I have to reconcile them to see them.
Now I need to make sure my inserts go to my version.
Thank you all for the help.