<?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 Re: How To Verify That A Feature Service's Version Was Changed in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573760#M73479</link>
    <description>&lt;P&gt;Try using a layer's connection properties?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
lay = mp.listLayers()[0]
print(lay.connectionProperties["connection_info"]["version"])
#dbo.DEFAULT&lt;/LI-CODE&gt;&lt;P&gt;Try checking it before and after running your changer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Caveat here is I've never worked with branch-versioned stuff, but this is how it works for traditional versioning.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2025 22:10:11 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2025-01-08T22:10:11Z</dc:date>
    <item>
      <title>How To Verify That A Feature Service's Version Was Changed</title>
      <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573756#M73478</link>
      <description>&lt;P&gt;Hello and Happy New Year!&lt;/P&gt;&lt;P&gt;I am writing a Python script that ingests a layer from a branch-versioned feature service, changes the version, and then updates the data. I've not found any way to verify that &lt;STRONG&gt;arcpy.ChangeVersion_management()&lt;/STRONG&gt; actually changed the version, other than assuming that no exception being thrown means it was successful.&lt;/P&gt;&lt;P&gt;There is no workspace property on the feature layer's &lt;STRONG&gt;Describe&lt;/STRONG&gt; object, and no other properties other than &lt;EM&gt;canVersion&lt;/EM&gt; and &lt;EM&gt;isVersioned.&amp;nbsp;&lt;/EM&gt;Has anyone else encountered this and found a way to check the active version? Thanks&lt;/P&gt;&lt;P&gt;- Jack C&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 22:01:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573756#M73478</guid>
      <dc:creator>__JackCharde__</dc:creator>
      <dc:date>2025-01-08T22:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: How To Verify That A Feature Service's Version Was Changed</title>
      <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573760#M73479</link>
      <description>&lt;P&gt;Try using a layer's connection properties?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
lay = mp.listLayers()[0]
print(lay.connectionProperties["connection_info"]["version"])
#dbo.DEFAULT&lt;/LI-CODE&gt;&lt;P&gt;Try checking it before and after running your changer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Caveat here is I've never worked with branch-versioned stuff, but this is how it works for traditional versioning.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 22:10:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573760#M73479</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-01-08T22:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: How To Verify That A Feature Service's Version Was Changed</title>
      <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573867#M73481</link>
      <description>&lt;P&gt;Here is a function I use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_workspace(desc, version) -&amp;gt; tuple[str, str]:
    if getattr(desc, "dataType", None) == "ShapeFile":
        return desc.path, "folder"
    if desc.path.casefold().startswith("http"):
        if not version or version.casefold() == "sde.default":
            return desc.path, "service"
        else:
            return f"{desc.path};version={version}", "service"
    else:
        return get_workspace_desc(desc).catalogPath, "gdb"


def active_edits(self, layer):
	# Dont ask me how this works, I forget
	if not layer or not layer.connectionProperties:
		return True
	else:
		return False

def change_version(self, layer_name):
        # Note, this does not appear to work with a layer object, use the layer name
        if self.workspace_version is None or self.workspace_version.casefold() == "sde.default":
            return None
        if not self.is_service:
            return None
        # Not sure if the normalization is needed
        logger.debug(self.workspace)
        pth = get_workspace(arcpy.Describe(layer_name), None)[0]
        logger.debug(pth)
        if os.path.normpath(self.workspace) != os.path.normpath(pth):
            return None

        logger.debug(f"Changing {getattr(layer_name, 'name', layer_name)} to {self.workspace_version}")
        result = arcpy.ChangeVersion_management(layer_name, "BRANCH", self.workspace_version, None, "EXCLUDE")[0]
        logger.debug(result)

        if self.active_edits(result):
            logger.error("Cannot preform Calculation with Active Edit Session")
            raise SystemExit(1)
        try:
            logger.debug(result.connectionProperties)
            if result.connectionProperties["connection_info"]["version"] != self.workspace_version:
                logger.error("Version was not changed, exiting")
                raise SystemExit(1)
        except Exception as e:
            logger.error(f"Unable to change version. {e}")
            raise SystemExit(1)
        return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2025 11:45:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1573867#M73481</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2025-01-09T11:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: How To Verify That A Feature Service's Version Was Changed</title>
      <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1574582#M73524</link>
      <description>&lt;P&gt;Hey Alfred,&lt;/P&gt;&lt;P&gt;Thanks for the response! Implementing an ArcGISProject into the script was my next attempt and I should have tried that before posting because indeed I can get the version of a layer in the ToC.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 22:28:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1574582#M73524</guid>
      <dc:creator>__JackCharde__</dc:creator>
      <dc:date>2025-01-10T22:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: How To Verify That A Feature Service's Version Was Changed</title>
      <link>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1574583#M73525</link>
      <description>&lt;P&gt;Hey Mike,&lt;/P&gt;&lt;P&gt;This is a great code reference for future use, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 22:31:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-verify-that-a-feature-service-s-version-was/m-p/1574583#M73525</guid>
      <dc:creator>__JackCharde__</dc:creator>
      <dc:date>2025-01-10T22:31:17Z</dc:date>
    </item>
  </channel>
</rss>

