This issue or similar ones have been previously been reported to ESRI (Esri Case #03242592) by me. I thought it was fixed at 11.x. This was also reported to this group (with no solution) back in 2019 (arcpy.da.Editor Not Working Properly)
I am working on a project to develop best practices for migrating a series of tools that run in an ArcPro/Fabric GDB environment to an ArcPro/Fabric branched version environment (ArcProFabric 3.1+/Enterprise 11.1+). I am running into a consistently inconsistent problem with converting my Scripts/tools. Attached is a zip file the contains a toolbox with the tool (UpdateCogoArea) and associated python script (UpdateCoGoArea.py).
For selected taxlots this tool calculates two attributes (TaxlotFeet/TaxlotAcre) from the CalculatedArea field and calculates the MapAcres field from the Shape_Area field. It’s a simple calculation and the three attributes are required for our state standard.
Tool Requirements: ActiveBranchVersion, Selected Taxlots (Fabric) with the CalculatedArea field and the three required fields ('TaxlotAcre',"TaxlotFeet",'MapAcre’) all numeric/double. You can run this tool on your data if you add the fields and change the reference to your parcel fabric layer.
Options: Within the python script you can change how the tool runs. It can either use the CalculateFields tool or use “arcpy.da.Editor” with an update cursor. (Line 42/43) In the script (useCalcFields = True or False.)
Issues: The CalcFields Option works great. I do not set the edit environment etc. The UpdateCusor option causes strange results. When you run it a) the attributes are not updated (however if you open and close the session) they will be. b) if you spatially select the polygons and try to look at the attributes the table will come up with two records selected but you will NOT be able to see them (unless you open and close the project).
My Question?
- Am I referencing the versioned workspace incorrectly? (I display the version and workspace as part of the script messages)
- Am I using the UpdateCursor with the arcpy.da.Editor incorrectly ?
- Is there a problem with our services or the software ?
To Test:
- Add the three fields ('TaxlotAcre',"TaxlotFeet",'MapAcre’) to your ParcelFabric parceltype.
- Edit the UpdateCogoArea script and tool to reference YOUR parcel fabric layer (my layer is called Taxlot) make sure the python script has useCalcFields = false (line 43). This will run the tool using the da.editor and update cursor option.
- Open the project, select a couple fabric polygons (with calculatedarea populated) and run the tool (messages are below).
- See if the calcs worked, with the table open spatially select your polygons again – Note if the fields are updated and attributes updated. Close and re-open the project. Does this look and act as expected ?
- Select the polygons and calculate the three fields equal to zero.
- Close the project. Edit the python script and change useCalcFields = True and save
- Open the project. Select the polygons and re-run the tool.
- Review the results (Everything should operate as expected).
For those that do not want to to the test here the two alternative. Again CalculateFields works but UpdateCursor and edit session does not. I have included tool messages for reference after the following code.
# -------- This works ---------
if useCalcFields:
arcpy.management.CalculateFields(mapTaxlotLyr, "Python3",[["TaxlotAcre", "round(!CalculatedArea! / 43560,2)"],["TaxlotFeet", "round(!CalculatedArea!,2)"],["MapAcres", "round(!Shape__Area! / 43560,2)"]])
arcpy.AddMessage('Used CalcFields')
sys.exit('Calcone')
# ----------- This does NOT work ----------
# get workspace and version
thisProject = arcpy.mp.ArcGISProject("CURRENT")
Map= thisProject.activeMap
mapTaxlotLyr = Map.listLayers("Taxlot")[1]
# set data source and version (Not Needed for "CalcFields" but used with edit session)
MapLayerDataSource = mapTaxlotLyr.dataSource
lastslash = MapLayerDataSource.rfind("/")
WorkSpace = MapLayerDataSource[:lastslash]
arcpy.AddMessage("WorkSpace: " + WorkSpace)
AfterVEq = MapLayerDataSource.rfind("VERSION=") + 8
Version = MapLayerDataSource[AfterVEq:]
BeforeVID = Version.rfind(";")
Version = Version[:BeforeVID]
arcpy.AddMessage ("Version: " + str(Version))
# Do the edit
edit = arcpy.da.Editor(WorkSpace)
edit.startEditing(with_undo=False, multiuser_mode=True)
edit.startOperation()
with arcpy.da.UpdateCursor(mapTaxlotLyr,['CalculatedArea','shape__Area','TaxlotAcre',"TaxlotFeet",'MapAcres','Taxlot']) as cursor:
for row in cursor:
row[2] = 0
row[3] = 0
row[4] = 0
if row[0] != None:
row[2] = round(row[0] / 43560,2)
row[3] = round(row[0],2)
if row[1]!= None:
row[4] = round(row[1] / 43560,2)
arcpy.AddMessage('Taxlot: ' + row[5])
arcpy.AddMessage('TaxlotAcre: ' + str(row[2]))
arcpy.AddMessage('TaxlotFeet: ' + str(row[3]))
arcpy.AddMessage('MapAcre: ' + str(row[4]))
cursor.updateRow(row)
# End Edit Session
edit.stopOperation()
edit.stopEditing(save_changes=True)
Below are my messages referencing the version and versioned workspace...

I would VERY much appreciate ANY Help. Thanks