Hi,
I have a feature class without version and archiving. When I attempt the code below, it threw a workspace already in transaction mode error. I tested with all combination of
nothing works. the only thing however that did worked is using arcpy.InsertCursor instead of arcpy.da.InsertCursor
def main():
try:
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, False)
edit.startOperation()
point = arcpy.Point(111,-60)
pointGeom = arcpy.PointGeometry(point,"4326")
row = []
row.append('test')
row.append(pointGeom)
cursor = arcpy.da.InsertCursor(config.FC, ['testfield', 'SHAPE@XY'])
cursor.insertRow(row)
edit.stopOperation()
edit.stopEditing(True)
except Exception as e:
#error handling
The following also did not work
I would like to roll back if an error occurred during a truncate and append. I tested with DeleteFeature, neither worked.
with arcpy.da.Editor(workspace) as edit:
arcpy.TruncateTable_management(config.PropertyFC)
#arcpy.DeleteFeatures_management(config.PropertyFC)
arcpy.Append_management(config.PropertyGDB, config.PropertyFC,"TEST")
Can someone advise?
Thanks
Hi Victor,
Ok...arcpy has a tendency to hold onto cursor objects. But it does treat arcpy.da.InsertCursor as different to arcpy.InsertCursor, so it looks like it is holding onto a da cursor either from earlier in the script or from an earlier iteration.
Things to check:
Several things to try:
def main():
workspace = r'???'
edit = arcpy.da.Editor(workspace)
point = arcpy.Point(111,-60)
pointGeom = arcpy.PointGeometry(point,"4326")
try:
edit.startEditing(False, False)
edit.startOperation()
cursor = arcpy.da.InsertCursor(config.FC, ['testfield', 'SHAPE@XY'])
row = ['test', pointGeom]
cursor.insertRow(row)
edit.stopOperation()
edit.stopEditing(True)
del cursor, row
except Exception as e:
#error handling
A another way would be:
def main():
workspace = r'???'
edit = arcpy.da.Editor(workspace)
point = arcpy.Point(111,-60)
pointGeom = arcpy.PointGeometry(point,"4326")
try:
edit.startEditing(False, False)
edit.startOperation()
cursor = arcpy.da.InsertCursor(config.FC, ['testfield', 'SHAPE@XY'])
row = cursor.newRow()
row.SetValue('testfield', 'test')
row.SetValue('SHAPE@XY', pointGeom)
edit.stopOperation()
edit.stopEditing(True)
del cursor, row
except Exception as e:
#error handling
Onto this one:
The following also did not work
I would like to roll back if an error occurred during a truncate and append. I tested with DeleteFeature, neither worked.
with arcpy.da.Editor(workspace) as edit: arcpy.TruncateTable_management(config.PropertyFC) #arcpy.DeleteFeatures_management(config.PropertyFC) arcpy.Append_management(config.PropertyGDB, config.PropertyFC,"TEST")
Couple of questions:
Well, I hope that this helps.
Michael
Thank you for that, however I have tried as you have suggested but nothing worked. The example I was reduce to be as simple as possible from the original code therefore nothing was running before it.
The data is retrieve from a rest api and pushed into a FC, no gdb or shapefile involved.
Unfortunately due to time constraint, i had to work around this.
Again thank you for your time
No problems Victor, happy to help.
Sorry we couldn't find the solution.