<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Branch Versioning Child Version Bulk Update using the ArcGIS Python API in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/branch-versioning-child-version-bulk-update-using/m-p/1292337#M67715</link>
    <description>&lt;P&gt;Hello. We recently migrated to branch versioning, and I noticed our Python automation scripts no longer work because the scripts can't write against the DEFAULT Branch Version. I researched and found a possible solution, but I am having trouble with my script with changing the DEFAULT Parent Version to the Child Version to make bulk updates and then reconcile/post back into the DEFAULT Parent Version. I am unsure if I should use the ArcGIS Portal feature service or the feature class to perform the version change. I attached my proposal code below. The error message is cryptic and difficult to troubleshoot | "RuntimeError: Object: Error in executing tool"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer, Feature
import arcpy

# Connect to the GIS
gis = GIS(url="YOUR PORTAL URL", username="YOUR USERNAME", password="YOUR PASSWORD")

# Define version names
parent_version = "sde.DEFAULT"
child_version = "CHILD_VERSION"

# Get the feature service
service_id = "SERVICE ID"
service = gis.content.get(service_id)
layer = service.layers[0]

# Switch to the child version for editing
arcpy.management.ChangeVersion(layer, "BRANCH", f"{child_version}", None, "INCLUDE")

# Fetch the features to be updated
features = layer.query()  # You may need to refine this query

# Create a dictionary to match the prefixes to the correct "St_PreTyp" value
prefixes = {
    "Interstate": "Interstate"}

# Loop through the features
for feature in features:
    # Get the "St_Name" value
    st_name = feature.attributes["St_Name"]
    
    if st_name is not None:
        update_required = True
        # Check if St_Name contains only the Spanish prefix
        if st_name.strip() in ["Calle"]:
            update_required = False  # No update required
        # If update is required, loop through the prefixes to find a match
        if update_required:
            for prefix, pretyp in prefixes.items():
                if st_name.startswith(prefix):
                    # If additional characters are present, parse and update the fields
                    feature.attributes["St_PreTyp"] = pretyp
                    feature.attributes["St_Name"] = st_name.replace(prefix, "").lstrip().replace("Highway", "").lstrip()
                    break
    else:
        feature.attributes["St_PreTyp"] = None

# Submit the edits
layer.edit_features(updates=features)

# After performing your operations, reconcile and post the changes from the child version to the parent version
arcpy.ReconcileVersions_management(database, "ALL_VERSIONS", parent_version, child_version, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION")

# Switch back to the parent version
arcpy.management.ChangeVersion(layer, "BRANCH", parent_version, None, "INCLUDE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2023 22:05:13 GMT</pubDate>
    <dc:creator>ArizonaGIS</dc:creator>
    <dc:date>2023-05-23T22:05:13Z</dc:date>
    <item>
      <title>Branch Versioning Child Version Bulk Update using the ArcGIS Python API</title>
      <link>https://community.esri.com/t5/python-questions/branch-versioning-child-version-bulk-update-using/m-p/1292337#M67715</link>
      <description>&lt;P&gt;Hello. We recently migrated to branch versioning, and I noticed our Python automation scripts no longer work because the scripts can't write against the DEFAULT Branch Version. I researched and found a possible solution, but I am having trouble with my script with changing the DEFAULT Parent Version to the Child Version to make bulk updates and then reconcile/post back into the DEFAULT Parent Version. I am unsure if I should use the ArcGIS Portal feature service or the feature class to perform the version change. I attached my proposal code below. The error message is cryptic and difficult to troubleshoot | "RuntimeError: Object: Error in executing tool"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer, Feature
import arcpy

# Connect to the GIS
gis = GIS(url="YOUR PORTAL URL", username="YOUR USERNAME", password="YOUR PASSWORD")

# Define version names
parent_version = "sde.DEFAULT"
child_version = "CHILD_VERSION"

# Get the feature service
service_id = "SERVICE ID"
service = gis.content.get(service_id)
layer = service.layers[0]

# Switch to the child version for editing
arcpy.management.ChangeVersion(layer, "BRANCH", f"{child_version}", None, "INCLUDE")

# Fetch the features to be updated
features = layer.query()  # You may need to refine this query

# Create a dictionary to match the prefixes to the correct "St_PreTyp" value
prefixes = {
    "Interstate": "Interstate"}

# Loop through the features
for feature in features:
    # Get the "St_Name" value
    st_name = feature.attributes["St_Name"]
    
    if st_name is not None:
        update_required = True
        # Check if St_Name contains only the Spanish prefix
        if st_name.strip() in ["Calle"]:
            update_required = False  # No update required
        # If update is required, loop through the prefixes to find a match
        if update_required:
            for prefix, pretyp in prefixes.items():
                if st_name.startswith(prefix):
                    # If additional characters are present, parse and update the fields
                    feature.attributes["St_PreTyp"] = pretyp
                    feature.attributes["St_Name"] = st_name.replace(prefix, "").lstrip().replace("Highway", "").lstrip()
                    break
    else:
        feature.attributes["St_PreTyp"] = None

# Submit the edits
layer.edit_features(updates=features)

# After performing your operations, reconcile and post the changes from the child version to the parent version
arcpy.ReconcileVersions_management(database, "ALL_VERSIONS", parent_version, child_version, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION")

# Switch back to the parent version
arcpy.management.ChangeVersion(layer, "BRANCH", parent_version, None, "INCLUDE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 22:05:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/branch-versioning-child-version-bulk-update-using/m-p/1292337#M67715</guid>
      <dc:creator>ArizonaGIS</dc:creator>
      <dc:date>2023-05-23T22:05:13Z</dc:date>
    </item>
  </channel>
</rss>

