error return without exception set

20511
17
04-14-2014 10:35 AM
TonyAlmeida
Occasional Contributor II
I have the following code.
The code works great on a shapefile but as soon as i change the workspace to a SDE sqlexpress datatbase i get the following error.
Traceback (most recent call last):
  File "C:\GIS\Python Scripts\AddressPoints\Point_2_Ca.py", line 125, in <module>
    edit.stopOperation()
SystemError: error return without exception set


The error is not specific on where the problem is, I've searched but i am unable to find the problem. where is the problem and how can i fix it to run with out errors?
As i mentioned before the code runs great against a shapefile and running against a shapefile takes about 4-6 seconds.
When i switch it to a SDE sqlexpress datatbase it takes 4 minutes then runs into the error. There is only 48 features in the SDE sqlexpress datatbase so the database is not very big. Why is this?


import arcpy
from arcpy import env
import time
import datetime
import pythonaddins
import os

fc = "TonyTwoWay.DBO.TT"
workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TonyTwoWay (VERSION:dbo.DEFAULT)"
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False

# Start an edit session. Must provide the worksapce.
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)

# Start an edit operation
edit.startOperation()

input = arcpy.GetParameterAsText(0)

rows = arcpy.SearchCursor(input)
for row in rows:
    geom = row.Shape
    X = geom.centroid.X
    Y = geom.centroid.Y
del rows, row
   
row_values = (X, Y, (X, Y))
cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY"])
cursor.insertRow(row_values)
del cursor

####Select by location on parcels with created point
Parcellyr = "Taxparcels"

arcpy.MakeFeatureLayer_management(Parcellyr, "in_memory\Parcel layer")
entries = int(arcpy.GetCount_management(fc).getOutput(0))

for i in xrange(entries):
    arcpy.MakeFeatureLayer_management(fc, "in_memory\point layer", "\"OBJECTID\"={}".format(str(i) + ""))
    arcpy.SelectLayerByLocation_management("in_memory\Parcel layer", "INTERSECT", "in_memory\point layer", "", "NEW_SELECTION")
    #if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr) 

arcpy.CopyFeatures_management("in_memory\Parcel layer", "in_memory\Sel_Par")
table = "Vector.DBO.PARCELADMIN"
try:
    arcpy.AddJoin_management("in_memory\Sel_Par", "ACCOUNT", table, "Acct", "KEEP_COMMON")
except BaseException as e:
    pass

arcpy.CopyFeatures_management("in_memory\Sel_Par","in_memory\ParLYR")
arcpy.MakeFeatureLayer_management("in_memory\ParLYR", "in_memory\Par")


#### populates fields

add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","Predir","StreetType","Postdir", "SubName", "SiteCity", "SiteZip", "SubName"]

# fix args
if not isinstance(add_fields, list):
    # from script tool
    add_fields = add_fields.split(';')

# do not need this scratch file
fcOutput = r'C:\Temp\Default.gdb\temp_join' #'temp_join' when using workspace = r"C:\Temp\default.gdb"
arcpy.SpatialJoin_analysis("in_memory\Par", "in_memory\point layer", fcOutput, 'JOIN_ONE_TO_MANY', 'KEEP_COMMON')

# grab oid field from points
oid_t = arcpy.Describe(fc).OIDFieldName

Field4 = "SubNum" #Field from spaital Join
Field4a = "SiteSubNum"
#Field5 = "City" #Field from spaital Join
#Field5a = "BusinsName"

# init rowW and rowR
curR = arcpy.SearchCursor(fcOutput)
join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR])
del curR

Fields = ["SubNum","City",]

rows = arcpy.da.SearchCursor(fcOutput, Fields)
for row in rows:
    Num1 = rows[0]
    #Num2 = rows[1]
    
# Now update the new target
curW = arcpy.UpdateCursor(fc)
for row in curW:
    t_oid = row.getValue(oid_t)
    if t_oid in join_dict:
        for f in add_fields:
            row.setValue(f, join_dict[t_oid][add_fields.index(f)])
            row.setValue('GIS_STEW', "Canyon Co")
            row.setValue('IssuedBy', "TA")
            row.setValue('Status', "Active")
            row.setValue('StartDate', datetime.datetime.now().strftime('%m/%d/%Y'))
            row.setValue('SiteState', "ID")
            row.setValue('SiteCounty', "Canyon")
            row.setValue('StreetName', row.SiteStreet + " " + row.StreetType)
            row.setValue('Verified', "Yes,TA")
            row.setValue(Field4a, Num1)
            #row.setValue(Field5a, Num2)
        #else:
            #row.StreetName = curR.SiteStreet
    curW.updateRow(row)
del row, curW, rows


#arcpy.SelectLayerByAttribute_management(Parcellyr, "CLEAR_SELECTION")
arcpy.Delete_management("in_memory\Parcel layer")
arcpy.Delete_management("in_memory\point layer")
arcpy.Delete_management("in_memory\Sel_Par")
arcpy.Delete_management("in_memory\ParLYR")
arcpy.Delete_management("in_memory\Par")
#arcpy.Delete_management(r'in_memory\temp_join')

# Stop the edit operation.
edit.stopOperation()

# Stop the edit session and save the changes
edit.stopEditing(True)
              
Tags (2)
17 Replies
WilliamCraft
MVP Regular Contributor
You may be seeing this error because the dataset is not registered as versioned within the SQL Server geodatabase.  Can you try ONE of the following?

1. Change the edit.startEditing(True) line to edit.startEditing(True,False)

or

2. Register the data you are trying to edit as versioned (either manually from ArcGIS Desktop or via Python before opening the edit session)

The syntax for the startEditing tool is startEditing ({with_undo}, {multiuser_mode}), which is explained here.  I think the issue is that you aren't specifying the right boolean for the multiuser mode.  "When False, you have full control of editing a nonversioned, or versioned dataset.  If your data is nonversioned and you use stopEditing(False), your edit will not be committed (otherwise, if set to True, your edits will be committed).  The default value is True."
0 Kudos
TonyAlmeida
Occasional Contributor II
crafty762 thanks for the reply.

The data is registered as versioned. That was one of the things i saw come up when i searched for the error.

I changed the edit.startEditing(True) line to edit.startEditing(True,False) and got pasted the error.
Code seems to run fine, but i get this error now.

Traceback (most recent call last):
  File "C:\GIS\Python Scripts\AddressPoints\Create_Point_2_Ca.py", line 34, in <module>
    cursor.insertRow(row_values)
RuntimeError: workspace already in transaction mode
0 Kudos
MathiasKP
New Contributor

With versioned SDE data in an Oracle database I use:

edit.startEditing(False, True)

with unversioned SDE data in an Oracle database I use

edit.startEditing(False, False)

these settings work for me

0 Kudos
TonyAlmeida
Occasional Contributor II
The error"RuntimeError: workspace already in transaction mode" happens when i have my data as versioned and set the line to edit.startEditing(True,False).


I have unversioned the data and change the edit.startEditing(True) line to edit.startEditing(True,False). I get the same error.
    edit.stopOperation()
SystemError: error return without exception set


i have registered as versioned and changed the line back to edit.startEditing(True) now i get this error,
edit.stopOperation()
SystemError: error return without exception set


So no matter which way i change the code i get the same error. Anyone have any other ideas what's going on and how can i fix this?
0 Kudos
ShannonPorter
New Contributor III

Is the user already in an edit session in Arcmap before your script starts editing?  If so then I would check with tech support and look into

[BUG-000089820: The Editor class from ArcPy returns an error message when the 'stopEditing()' command is executed when an existing edit session is open on the same workspace. "RuntimeError: Start edit session."]

I had a situation where the user is already in an edit session so I didn't think I had to start editing in python script but the tech support person had me start editing.  However when I went to stopEditing it failed with the error you received and they pointed out the bug.  In my case I just removed the stopediting from my script and it seems to be functioning.

0 Kudos
BryanPrice3
New Contributor
The error"RuntimeError: workspace already in transaction mode" happens when i have my data as versioned and set the line to edit.startEditing(True,False).


I have unversioned the data and change the edit.startEditing(True) line to edit.startEditing(True,False). I get the same error.
    edit.stopOperation()
SystemError: error return without exception set


i have registered as versioned and changed the line back to edit.startEditing(True) now i get this error,
edit.stopOperation()
SystemError: error return without exception set


So no matter which way i change the code i get the same error. Anyone have any other ideas what's going on and how can i fix this?


Did you ever get an answer to this? We are having a similar issue. It doesn't always fail either. On some environments it fails with this error sometimes, and on others it never fails.
0 Kudos
TonyAlmeida
Occasional Contributor II

I have not, i am still messing around with it.

0 Kudos
AllenCousins
New Contributor II

I'm also experiencing the same problem.  Did anyone ever get an answer to this?

0 Kudos
LangDeng
New Contributor

I had the same issue:

  1. edit.stopOperation() 
  2. SystemError: error return without exception set 

My problem and solution:  I forgot edit.startOperation()!

Workspace already in transaction mode:   my problem and solution: 

Check to make sure the field that need to be updated, surely exist.   Add an If to check the filed, then

the problem is gone,

lang

0 Kudos