Still having issues 3 years later at 10.4.1. I'm trying to use an update cursor on an sde versioned database. Here's a test script:
streetCLInput = r'Database Connections\brandon_edits.sde\oki.sde.StreetCL'
workspace = r'Database Connections\brandon_edits.sde'
import arcpy
arcpy.MakeFeatureLayer_management(streetCLInput, 'streets')
arcpy.ChangeVersion_management("streets", "TRANSACTIONAL", "brandon_edits.brandon")
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()
with arcpy.da.UpdateCursor('streets', ['objectid','suffix'], 'objectid = 11040') as cursor:
for row in cursor:
row[1] = ''
cursor.updateRow(row)
edit.stopOperation()
edit.stopEditing(True)
print('Script Complete')
The script crashes at line 10, but its because of line 5. Comment out line 5 and the script works, except the edits are made to the default version.
Here's another script basically copied and pasted from here : http://pro.arcgis.com/en/pro-app/arcpy/data-access/editor.htm with edits to change the version.
import arcpy
fc = r'Database Connections\brandon_edits.sde\oki.sde.StreetCL'
workspace = r'Database Connections\brandon_edits.sde'
arcpy.MakeFeatureLayer_management(fc, 'streets')
#arcpy.ChangeVersion_management("streets", "TRANSACTIONAL", "brandon_edits.brandon")
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True, True)
# Start an edit operation
edit.startOperation()
# Insert a row into the table.
with arcpy.da.InsertCursor("streets", ('name')) as icur:
icur.insertRow(['New Test'])
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
The script "works" with line 5 commented out except again the edits are made to the default version. With line 5 uncommented, the script fails.
So how do you edit an sde versioned dataset with arcpy and not edit the default version? Any help would be much appreciated. (I'm starting to think the versioning is more hassle than its worth.)
I found the problem, in Catalog, the connection to the versioned data was using the default version as the transactional version to automatically connect to. To change this, you need to change the geodatabase connection properties to point to the version you wish to edit by default. It's a little confusing and odd that the default behavior is to edit the parent version of the version you are connected to but whatever. Its working now.
I still think the above script should execute without having to edit any geodatabase connection properties.
Also see this: BUG-000101529 : The 'Make Feature Layer' geoprocessing tool fails when 64-bit Background Geoprocessing is utilized with ArcGIS 10.4.1. when using a sde database connection. Potentially fixed at 10.5.