Editing Session in ModelBuilder or Python?

674
3
09-19-2018 08:58 AM
JenniferReilly1
New Contributor II

Hello,

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
DarrenWiens2
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
JenniferReilly1
New Contributor II

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.

DanPatterson_Retired
MVP Esteemed 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

https://community.esri.com/groups/technical-support/blog/2013/07/29/64-bit-vs-32-bit-python-explaine... 

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