Debugging RuntimeError: workspace already in transaction mode from arcpy.da.UpdateCursor and ArcSDE feature classes?

With help I have found my solution, though the reasoning behind it is a bit blurry currently. In my code, creating a version through one SDE connection file and then creating the feature layer to be edited through another SDE connection file that is connected to the new version works. Also, edit.startEditing must have the variable 'multiuser_mode' set to true (the default). As I understand it, this variable indicates whether there can be multiple versions/users allowed for the layer. Since this is always true for an SDE feature layer, setting this variable to False causes an error.

Functioning code, where I test an update cursor:

import arcpy
import os
#Locals
P6featureName = r"PPGIS.Strux\PPGIS.Land_Projects_Parcels_P6"
Parent = "SDE.DEFAULT"
version = "SDE_Test"
Server = ***
Service = ***
user = ***
Pass = ***
SDE = "Database Connections\PipelinePathways.sde"
temploc = r"C:\E1B8\ScriptTesting\Workspace"
fil = "SDETempConn"

env.overwriteOutput = True

#Create Version
print "Creating version"
arcpy.CreateVersion_management (SDE, Parent, version, "PUBLIC")
VersionName = user.upper() + "." + version

#Create new connection
workspace = os.path.join (temploc, fil + ".sde")
print "Creating SDE connection"
arcpy.CreateArcSDEConnectionFile_management (temploc, fil, Server, Service, username = user, password = Pass, version = VersionName)

#Layers
P6feature = os.path.join (workspace, P6featureName)
arcpy.MakeFeatureLayer_management (P6feature, "P6lyr")

#Start editing
print "Initiating editing"
edit = arcpy.da.Editor (workspace)
edit.startEditing ()
edit.startOperation()

#Test Cursor
print "Testing cursor"
P6Cursor = arcpy.da.UpdateCursor ("P6lyr", ["NAME"])
for row in P6Cursor:
    print row[0]
del row
del P6Cursor

#Stop/save edits
edit.stopOperation()
print "Stopping editing"
edit.stopEditing("True")

#Switch to version
print "Switching version"
arcpy.ChangeVersion_management("P6lyr", "TRANSACTIONAL", Parent)

#Reconcile and post
print "Reconciling and posting"
arcpy.ReconcileVersions_management (workspace, "", Parent, VersionName, with_post = "POST", with_delete = "DELETE_VERSION")

Thanks to Ben Nadler for the help.


In my case the table we were inserting into was not registered with the geodatabase and was never going to be registered. Adding a primary key and identity column resolved this issue for us.