<?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: Using Cursors on Versioned Feature Class Layers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241651#M66280</link>
    <description>&lt;P&gt;I had these same problems. Upgrading to ArcGIS Pro 3.0.3 was the fix for me.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 18:09:58 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2022-12-15T18:09:58Z</dc:date>
    <item>
      <title>Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241603#M66278</link>
      <description>&lt;P&gt;I am using ArcGIS Pro 2.9.3.&amp;nbsp; I am a seasoned Python programmer, but need help meeting the following requirements:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Environment: A Python toolbox in an ArcGIS Pro project, opened by a user who is manually running the tools&lt;/LI&gt;&lt;LI&gt;A map in an ArcGIS Pro project contains several layers that come from feature classes in an enterprise geodatabase feature dataset which is registered as versioned (traditional)&lt;/LI&gt;&lt;LI&gt;Read the values of some unselected records in various layers in the map.&amp;nbsp; I will use arcpy.da.SearchCursor with a where clause.&lt;/LI&gt;&lt;LI&gt;Update some values of some unselected records in various layers in the map.&amp;nbsp; I will use arcpy.da.UpdateCursor, again with a where clause.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I cannot figure out what combination of strings that arcpy.da methods need, given my environment.&amp;nbsp; I will only know which map layer the user wants to work with at run-time.&amp;nbsp; Its data source will be a feature class in a versioned dataset on an enterprise&amp;nbsp; geodatabase.&amp;nbsp; Given the variables below, which values will make arcpy.da methods happy, so I can Search, Update, Insert, and Delete rows from a layer, regardless of selection, and still be able to see those changes within the map?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;projectName = "CURRENT"
project = arcpy.mp.ArcGISProject(projectName)
mapName = "Map"
map_ = next(filter(lambda m: m.name == mapName, project.listMaps()))
grpLayerName = "theGroup"
mapLayerName = "theLayer"
mapLayerLongName = "\\".join((grpLayerName, mapLayerName))
layer = next(filter(lambda lyr: lyr.longName == mapLayerLongName, map_.listLayers()))
dbName = "obfuscated"
schemaName = "adminUser"
datasetName = "bigDataSet"
datasetLongName = ".".join((dbName, schemaName, datasetName))
featClassName = "bigFeatureClass"
featClassLongName = ".".join((dbName, schemaName, featClassName))
sdePath = r"C:\Users\Myself\Documents\ArcGIS\Projects\BigProject"
sdeFileName = "enterprise.sde"
sdeFilePath = os.path.join(sdePath, sdeFileName)
desc = arcpy.da.Describe(layer)
# desc.catalogPath equals os.path.join(sdeFilePath, datasetLongName, featClassLongName)
# desc.path equals os.path.join(sdeFilePath, datasetLongName)
# SOMETIMES, however, an .sde file in a Temp path is seen, rather than the
# one in my project!
# desc.aliasName, baseName, file, and name all equal featClassLongName

arcpy.da.Editor(workspace argument?)
arcpy.da.UpdateCursor(in_table argument?)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried so many combinations of strings for the&amp;nbsp;&lt;EM&gt;workspace&lt;/EM&gt; and &lt;EM&gt;in_table&lt;/EM&gt; arguments, it's not even funny.&amp;nbsp; I get errors like:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;"Objects in this class cannot be updated outside an edit session"&lt;/LI&gt;&lt;LI&gt;"cannot open workspace"&lt;/LI&gt;&lt;LI&gt;"insufficient permissions" (even though the user editing is the owner)&lt;/LI&gt;&lt;LI&gt;Or I succeed with the edit, but the map can't see it until I go to Contents &amp;gt; right-click the database connection and select Refresh.&amp;nbsp; I'm okay refreshing the map or the table view, but I don't want to have to ask the user to refresh the connection&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any help, ideas, or guidance would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 16:57:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241603#M66278</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-12-15T16:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241651#M66280</link>
      <description>&lt;P&gt;I had these same problems. Upgrading to ArcGIS Pro 3.0.3 was the fix for me.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 18:09:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241651#M66280</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-12-15T18:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241760#M66284</link>
      <description>&lt;P&gt;I was having some similar errors working off sde data a while ago but I determined that my editing session inputs were backwards so I would make sure that those are correct from the editor documentation. That should get rid of the "Objects in this class cannot be updated outside an edit session" and "cannot open workspace" errors. Not sure about the insufficient permissions though.&lt;/P&gt;&lt;P&gt;Also I believe that with versioned enterprise data another user will not be able to see edits you make to your version until there has been a rec and post unless they have access to your version. In that case I still believe they would have to refresh the connection due to the edits not being made during their own session. However, if you are making the edits within the python window and you cannot see the results until refreshing the connection, I'm not sure how to fix that bug.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a snippet of my code for a similar type of project that it seems you are attempting with the edit session inputs I used for sde data. Let me know if this helps or if I missed the mark entirely.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;workspace = r"enterprise.sde"

edit = arcpy.da.Editor(workspace)

edit.startEditing(False, False)

edit.startOperation()

with arcpy.da.UpdateCursor(layername, "field") as cursor:
    for row in cursor:
        argument

edit.stopOperation()

edit.stopEditing(True)&lt;/LI-CODE&gt;&lt;P&gt;Nicole&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 22:07:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241760#M66284</guid>
      <dc:creator>NicoleV</dc:creator>
      <dc:date>2022-12-15T22:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241796#M66286</link>
      <description>&lt;P&gt;Okay, but if layername is the name of a layer as it appears in the table of contents, it will have a selection, which I need to ignore for the various Cursors.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 23:04:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241796#M66286</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-12-15T23:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241803#M66288</link>
      <description>&lt;P&gt;I spoke too soon.&amp;nbsp; Here is the code that worked for me, based on what you said.&amp;nbsp; Given a layer in a map, I can do this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;tableName = desc["catalogPath"]
fields = ["OBJECTID", "COMMENT"]
query = "OBJECTID IN ({0})".format(", ".join((str(objId) for objId in objectIds)))
eddy = arcpy.da.Editor(sdeFileName)
eddy.startEditing(True, True)
eddy.startOperation()
with arcpy.da.UpdateCursor(tableName, fields, query) as uCursor:
    for row in uCursor:
        row[1] = "Test Comment"
        uCursor.updateRow(row)
del uCursor
eddy.stopOperation()
eddy.stopEditing(True)
del eddy&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will modify a row that is not part of a selection!&amp;nbsp; Love it!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 23:24:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241803#M66288</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-12-15T23:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241978#M66293</link>
      <description>&lt;P&gt;Glad you found a solution! I recommend testing your error handling here. If there's an error in your edit session, it may not close properly without a try/except statement or using a with statement.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 14:33:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1241978#M66293</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-12-16T14:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1242418#M66308</link>
      <description>&lt;P&gt;My try blocks generally look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;eddy = arcpy.da.Editor(myWorkspace)
try:
    eddy.startEditing(False, False) # Values depend on workspace
    try:
        # Operation 1
        eddy.startOperation()
        try:
            with arcpy.da.UpdateCursor(in_table1, fields1, query1) as uCursor:
                for row in uCursor:
                    # do something
                    uCursor.updateRow(row)
            eddy.stopOperation()
        except:
            eddy.abortOperation()
            raise
        finally:
            del uCursor

        # Operation 2
        eddy.startOperation()
        try:
            with arcpy.da.UpdateCursor(in_table2, fields2, query2) as uCursor:
                for row in uCursor:
                    # do something
                    uCursor.updateRow(row)
            eddy.stopOperation()
        except:
            eddy.abortOperation()
            raise
        finally:
            del uCursor
        eddy.stopEditing(True)
    except:
        eddy.stopEditing(False)
        raise
finally:
    del eddy&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Updated to show how I&amp;nbsp;&lt;EM&gt;now&lt;/EM&gt; work my try/except/finally blocks.&amp;nbsp; If anything goes wrong, the entire transaction is rewound and the database is left as it was, which makes this work well.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 22:16:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1242418#M66308</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2023-06-08T22:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1339357#M68989</link>
      <description>&lt;P&gt;Hi Roger, did this edit the selected features in the default version? Or does it focus on only the version in the project?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 21:26:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1339357#M68989</guid>
      <dc:creator>mejohnson22</dc:creator>
      <dc:date>2023-10-18T21:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Cursors on Versioned Feature Class Layers</title>
      <link>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1339437#M68992</link>
      <description>&lt;P&gt;That's a great question.&amp;nbsp; I don't work with any other versions than DEFAULT and that's because I don't know how to make versions easy.&amp;nbsp; In ArcGIS Desktop you had to modify your database connection (.sde) file and specify which version you were using.&amp;nbsp; There was also a version toolbar.&amp;nbsp; I think the version that is affected is the version used by the layer you're editing (if you specify a layer name for UpdateCursor) or the version tied to the .sde file if you're using a full-path to the feature class.&amp;nbsp; It's worth testing for sure.&lt;/P&gt;&lt;P&gt;Most of what I know I found out by reading, asking, trying, and making lots of mistakes.&amp;nbsp; If I was in your shoes, knowing this operation is important but volatile, I would set up some stuff.&amp;nbsp; I'd create a test dataset, a few test feature classes, with a few fields, make the dataset versioned (and which kind?), and try these changes in your code.&amp;nbsp; But a word of warning in determining if something worked or not: I have seen many cases where the change performed by Python isn't visible in the map, isn't visible after a refresh, isn't visible even after refreshing the version in the map, and isn't visible till after I close out Pro and reopen it.&amp;nbsp; I don't know why.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 03:38:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-cursors-on-versioned-feature-class-layers/m-p/1339437#M68992</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2023-10-19T03:38:28Z</dc:date>
    </item>
  </channel>
</rss>

