Has anyone have this problem? I created a python script, and it runs fine in a python interface or as a python tool in Arcmap, but when I convert it to a geoprocessing service it won't run. Furthermore, the error it gives it's unclear:
RuntimeError: Objects in this class cannot be updated outside an edit session
This error doesn't make sense because 1. the process is done in an editing session, and 2. it works as a standalone script or as a python tool.
Below is the code in case you want to take a look, but again it runs fine so the problem seems to be in the geoprocessing service step.
import arcpy arcpy.env.overwriteOutput = True # If needed create a connection file to the sde geodatabase if not arcpy.Exists('connect.sde'): arcpy.CreateDatabaseConnection_management('************') arcpy.env.workspace = r'connect.sde' # Input files districts = '*****' sites = '*****' arcpy.MakeFeatureLayer_management(sites, 'sites') # Start an editing session with arcpy.da.Editor(arcpy.env.workspace) as edit: fields = ['Name', 'totalsites', 'completedsites', 'SHAPE@'] with arcpy.da.UpdateCursor(districts, fields) as cursor: for row in cursor: name = row shape = row arcpy.SelectLayerByLocation_management('sites', 'WITHIN', shape) arcpy.CopyFeatures_management('sites', 'in_memory/selected') # count total and completed total = 0 completed = 0 siteFields = ['SITE_STATUS'] with arcpy.da.SearchCursor('in_memory/selected', siteFields) as cursor2: for row2 in cursor2: status = row2 total += 1 if status == '****': completed += 1 row = total row = completed cursor.updateRow(row) print 'Finished'
Thanks a in advance,