Editing Session in ModelBuilder or Python?

09-19-2018 08:58 AM
by Anonymous User
Not applicable


I'm trying to update a warranty field in my water meter feature class. It is supposed to add 20 years to the installation date. I used ModelBuilder to get the following code:

# Import arcpy module
import arcpy

# Local variables:
WMeter = "WMeter"
WMeter__2_ = WMeter

# Process: Calculate Field
arcpy.CalculateField_management(WMeter, "WarrantyDate", "DateAdd (\"yyyy\",20,[InstallDate] )", "VB", "")

However, I have to manually enter an edit session for this script to run correctly. If I'm not in an editing session it won't update the field the "WarrantyDate" field. Is there a way with Python or ModelBuilder to make it enter into an editing session? I've attempted:

edit = arcpy.da.Editor(workspace)edit.startEditing(False, True)edit.startOperation()

but I always get:

ERROR 001049: ASync operations not allowed while editing.

I have tried swapping out the true/false statements to see if it would change anything but it doesn't seem to matter if each is true or false, I get ASync either way.

Any help is greatly appreciated!

0 Kudos
3 Replies
MVP Honored Contributor

I'll caution you that an edit session is only required in certain circumstances, and this is probably not one of them.

Can you remove anything to do with an edit session and change your calculate field statement to:

arcpy.CalculateField_management(WMeter, "WarrantyDate", 'DateAdd("yyyy",20,[InstallDate] )', "VB", "")

I assume it's getting hung up on the escaped double-quote inside the statement, but not 100% sure.

0 Kudos
by Anonymous User
Not applicable

After posting my initial question I realized that I was editing a layer that is a participant in a geometric network. That would require an edit session, right? I then also tested out turning background processing on and off. If background processing was turned off, I could run the above script and it would run as expected. I guess my next step is figuring out how to get it to always run with background processing off, unless there is a better solution.

MVP Legendary Contributor

background geoprocessing can cause issues as you have found.

Some people want it, others find that certain tasks can't be done when it is on.

They use different versions of python in arcmap


You can make sure that you are using the correct version of python each time you run a script....or you can use ArcGIS Pro which is 64-bit and one version of python

0 Kudos