ChangeVersion not working? Pro 3.0.2

528
4
Jump to solution
03-22-2023 07:31 AM
Nathan_Freitas
New Contributor II

For reasons that are too numerable my organization has yet to update our database and sde feature layers to Pro versions. As such we cannot use attribute rules yet. One layer that our editor uses needs to have two fields updated using other fields. Doing it by hand is cumbersome when dealing with 400 plus features. Our work around so far has been to use calculate field tool which works but when the updated values require some high level expressions it can be discouraging. I developed a python script to do this for me and it runs just great for me but my coworkers keep getting the error that only the owner of sde.default can make edits.

edit.startEditing(True, True)

RuntimeError: Operation only allowed by the owner of the version [sde.DEFAULT]

 

I have set it up to use the arcpy.management.ChangeVersion. However, the same error appears even after using this function. Why isn't the version my coworkers are choosing not being used? Secondly I have noticed that if I have a selection in the feature layer once I change the version of the feature layer that selection is no longer valid. shouldn't the selection still be honored? The parameters are all set up through drop down lists and layer lists, so I am pretty confidant that the correct paths and names are being used. I find it strange I can use this script with no errors but others can't, I am not the owner of the sde.default version either.

Code:

workspaceName = arcpy.GetParameterAsText(0)

sdeParcel = arcpy.GetParameterAsText(1)
arcpy.AddMessage("parcel layer is {0}".format(sdeParcel))

version = arcpy.GetParameterAsText(2)

aprx = arcpy.mp.ArcGISProject("CURRENT")

arcpy.env.workspace = os.path.join(aprx.homeFolder,workspaceName)
arcpy.AddMessage("workspace path is {0}".format(arcpy.env.workspace))

arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False

arcpy.AddMessage(arcpy.management.GetCount(sdeParcel))

arcpy.management.MakeFeatureLayer(sdeParcel, "parcel_lyr")
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))


arcpy.management.ChangeVersion("parcel_lyr","TRANSACTIONAL",version)
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))

arcpy.management.SelectLayerByLocation("parcel_lyr","WITHIN_A_DISTANCE",sdeParcel, -1, "NEW_SELECTION")
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))

edit = arcpy.da.Editor(arcpy.env.workspace)
arcpy.AddMessage("edit object created")

edit.startEditing(True, True)
arcpy.AddMessage("startEditing initiated")

edit.startOperation()
arcpy.AddMessage("startOperation initiated")

with arcpy.da.UpdateCursor("parcel_lyr",["PIN", "PARCELNB", "TOWNSHIP", "SECTION_", "BLOCK", "PARCEL"]) as letsUpdate:
    arcpy.AddMessage("Update Object created")
    for each in letsUpdate:
        each[0] = each[2] + each[3] + each[4] + each[5]
        arcpy.AddMessage("PIN is {0}".format(each[0]))
        each[1] = "0"+each[0]
        letsUpdate.updateRow(each)


edit.stopOperation()
arcpy.AddMessage("stopOperaton Initiated")
edit.stopEditing(True)
arcpy.AddMessage("stopEditing Initiated")

del aprx, sdeParcel, edit, letsUpdate
 
 
Any suggestions? Or obvious lack of my understanding?
0 Kudos
1 Solution

Accepted Solutions
Nathan_Freitas
New Contributor II

Finally got it figured out.

Apparently the Geodatabase connection was not pointing to the right version. I had been selecting it through ArcCatalog application but Pro does not seem to recognize that selection. Figured it out when I did the connection through the arcCatalog panel in Pro.

Doing this actually eliminates the need to use ChangeVersion().

ChangeVersion does not seem to work when I try to use it in a script because the geodatabase connection is already established when this script is run. I can accept this workaround and wonder how others use ChangeVersion in scripts. Is my intended use an inappropriate use of this function?

 

View solution in original post

0 Kudos
4 Replies
ChrisUnderwood
Esri Contributor

The "version" you are referring to here,

arcpy.management.ChangeVersion("parcel_lyr","TRANSACTIONAL",version)

can have different Access Permissions.

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/create-modify-and-delete-ve...

Private: Only the owner can view and edit.
Protected: All users can view, but only the owner can edit.
Public: All users can view and edit.

Perhaps a different Access Permission setting is required for your editing scenario.

0 Kudos
Nathan_Freitas
New Contributor II

All versions with the exception of the sde.DEFAULT are public

0 Kudos
VaibhavS
New Contributor III

Hello @Nathan_Freitas . Could you try to modify your python script as per the below example and test once? 

arcpy.AddMessage("Activate new version")
arcpy.ChangeVersion_management(parcel_lyr, 'TRANSACTIONAL', version, '')

 

Please feel free to share your thoughts.

 

VaibhavS
0 Kudos
Nathan_Freitas
New Contributor II

Finally got it figured out.

Apparently the Geodatabase connection was not pointing to the right version. I had been selecting it through ArcCatalog application but Pro does not seem to recognize that selection. Figured it out when I did the connection through the arcCatalog panel in Pro.

Doing this actually eliminates the need to use ChangeVersion().

ChangeVersion does not seem to work when I try to use it in a script because the geodatabase connection is already established when this script is run. I can accept this workaround and wonder how others use ChangeVersion in scripts. Is my intended use an inappropriate use of this function?

 

0 Kudos