Geoprocessing service editing issue with arcpy.da.Editor

1797
11
Jump to solution
07-22-2021 09:38 AM
SreejithSreenivasan
New Contributor II

Have an issue with Geoprocessing service while doing start editing for more than one user at same time.

Input for Geoprocessing service is CAD drawing file(dgn/dwg) from web application. and Geoprocessing code is inserting the features to appropriate feature classes in enterprise geodatabase.

Enterprise geodatabase is versioned and editing is doing in SDE.Default. ArcGIS server version is 10.8

Please find the code snippets

eGeoDBWorkSpace = r"dbconnection.sde" #Enterprice geodatbase
----
edit = arcpy.da.Editor(eGeoDBWorkSpace)
try:
edit.startEditing(True, True) -- *Error
edit.startOperation()
inserCursor = arcpy.da.InsertCursor(polyFC,['ID',...., 'SHAPE@'])
for inRow in poly_insert_rows:
inserCursor.insertRow(inRow)
del inserCursor
arcpy.AddMessage("MP to Temp FC finished")
inserCursor = arcpy.da.InsertCursor(plynFC,['ID',...., 'SHAPE@')
for inRow in plyn_boundary_insert_rows:
inserCursor.insertRow(inRow)
del inserCursor
-------
-----
edit.stopOperation()
edit.stopEditing(True)
except Exception as err:
#arcpy.AddError(err)
if 'edit' in locals():
if edit.isEditing:
edit.stopOperation()
edit.stopEditing(False)

*Error : Getting error on this line , If editing started by one user request, between any other request came to the server.The new request will fail.

Really appreciate the support to resolve this issue.

 

0 Kudos
1 Solution

Accepted Solutions
DavinWalker2
Esri Contributor

I have run into a similar issue when trying to editing using an .sde.

Are you getting an error like this "The version has been redefined to reference a new database state"?

A solution is to edit a feature service instead? Publish the CAD drawing as a branched versioned dataset and edit that. You won't have to use edit.startEditing, edit.startOperation() workflow because the database editing will be taken care of by the ArcGIS Software. 

View solution in original post

0 Kudos
11 Replies
DanPatterson
MVP Esteemed Contributor

could you format your code to facilitate syntax errors 

Code formatting ... the Community Version - Esri Community


... sort of retired...
SreejithSreenivasan
New Contributor II
//Start
eGeoDBWorkSpace = r"dbconnection.sde" #database connection
----
-----
edit = arcpy.da.Editor(eGeoDBWorkSpace)
try:    
	edit.startEditing(True, True)    #*Error : Getting error on this line , If editing started by one user request, between any other request came to the server.The new request will fail.           
	edit.startOperation()
	inserCursor = arcpy.da.InsertCursor(polyFC,['ID',...., 'SHAPE@'])
	for inRow in poly_insert_rows:
		inserCursor.insertRow(inRow)
	del inserCursor
	arcpy.AddMessage("MP to Temp FC finished")
	inserCursor = arcpy.da.InsertCursor(plynFC,['ID',...., 'SHAPE@')
	for inRow in plyn_boundary_insert_rows:
		inserCursor.insertRow(inRow)
	del inserCursor		
-------
-----
	edit.stopOperation()		
	edit.stopEditing(True)		
except Exception as err:              
	if 'edit' in locals():  
		if edit.isEditing:  			
			edit.stopOperation()  			                  
			edit.stopEditing(False)	
------
------
arcpy.ClearWorkspaceCache_management()

//End
0 Kudos
JoeBorgione
MVP Emeritus

I suspect you are using a connection file to connect to your Enterprise Geodatabase.  You need to give the complete path to that connection file.  I use a connection file this way in python:

ws = r'\\complete path\to my\connection file\ConnectionFileName.sde'
edit = ws
That should just about do it....
0 Kudos
SreejithSreenivasan
New Contributor II

Hi JoeBorgione,

I am providing complete shared path. While doing the post I just modified the path. FYI,Code is working fine with single request at a time. Only problem is when there is concurrent users trying to edit the feature class.

0 Kudos
JoeBorgione
MVP Emeritus

Is the data versioned?

That should just about do it....
0 Kudos
SreejithSreenivasan
New Contributor II

Yes.It is versioned.I am editing in sde.default itself

0 Kudos
DavinWalker2
Esri Contributor

I have run into a similar issue when trying to editing using an .sde.

Are you getting an error like this "The version has been redefined to reference a new database state"?

A solution is to edit a feature service instead? Publish the CAD drawing as a branched versioned dataset and edit that. You won't have to use edit.startEditing, edit.startOperation() workflow because the database editing will be taken care of by the ArcGIS Software. 

0 Kudos
SreejithSreenivasan
New Contributor II

Hi DavinWalker2,

Yes. While running in desktop I am getting the same error message you have mentioned. But once I published as the geoprocessing service I am getting exception message as  "error return without exception set"(If there is concurrent requests).

Would like to know few more details about your solution.

  • A solution is to edit a feature service instead? So your suggestion is consume feature service inside my geoprocessing code. If we use feature service, Does the data update become transactional if we use feature service? Means I have 5 different feature class inserts required per request, if any one of the feature class update failed I would like to rollback all the other update happened on that request.
  • Branched versioned dataset? I didn't use this before, Does it required Portal also. In my current  environment we have ArcGIS server and Desktop only.
  • Does this mean that concurrent editing is not possible using arcpy.da.Editor in geoprocessing?

Please note that we are consuming this geoprocessing from ArcGIS JS API application. To immediately show the drawing file geometries over the base map with appropriate layer name and  symbology.

0 Kudos
DavinWalker2
Esri Contributor

A solution is to edit a feature service instead?  - Yes, I'm suggesting to use a feature service. You could just use the arcpy.da.InsertCursor and each row would be inserted independently. 

Branched versioned dataset? - Sorry disregard if you do not have ArcPro and Portal. 

Does this mean that concurrent editing is not possible using arcpy.da.Editor in geoprocessing? - I have not been able to get it to work correctly. this post also mentions the same or similar issue https://community.esri.com/t5/python-questions/multi-user-editing-in-arcpy/td-p/41607 

I hope you can figure out a workflow that best suits your requirements from the information I have provided.

0 Kudos