<?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: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382557#M69883</link>
    <description>&lt;P&gt;I can set up an editor class (&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/3.1/arcpy/data-access/editor.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/3.1/arcpy/data-access/editor.htm&lt;/A&gt;&amp;nbsp;this?)&amp;nbsp;&lt;BR /&gt;will&amp;nbsp;startEditing allow me to override the schema lock that exists and be able to use UpdateCursor? Reading the documentation in the link above, to my understanding the edit session is automatically handled within a with statement when using cursors, is this correct?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And for field calculator, is there a way to do this via arcpy? is it this?&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Feb 2024 22:37:26 GMT</pubDate>
    <dc:creator>EddX</dc:creator>
    <dc:date>2024-02-14T22:37:26Z</dc:date>
    <item>
      <title>Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382023#M69866</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I am updating a script which was used in ArcMap (python 2) to ArcPro (python 3). This script is ran through ArcPro with the layers loaded into the map.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a script which references a sde file (a table):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sTabName = "SDE_Company.ADMIN.Cadaster"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which firstly does a search cursor to get some data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.da.SearchCursor(sTabName, ('X','Y','Z')) as oRows&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;this works,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But later on I need to update sTabName so I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.da.UpdateCursor(sTabName, ("Z")) as oRows&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;the script hangs and gets stuck at this point. I have not used "&lt;SPAN&gt;edit.startOperation()" as the with statement should handle the editing opening and closing.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does ArcPro have more strict schema locking than ArcMap, which is causing this issue? This script worked fine in ArcMap.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I have ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if arcpy.TestSchemaLock(sTabName):&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;at the start of the script and sTabName has a lock on it, as it is open in the current map (it is also open by other user profiles in the business)&lt;BR /&gt;&lt;BR /&gt;Is this causing the issues/hang?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;How can I work around this to update the sTabName table?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 04:00:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382023#M69866</guid>
      <dc:creator>EddX</dc:creator>
      <dc:date>2024-02-14T04:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382169#M69876</link>
      <description>&lt;P&gt;Unfortunately you do need an editor class to use an update cursor on an enterprise geodatabase.&lt;/P&gt;&lt;P&gt;You can get around this by using Field Calculator.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 14:02:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382169#M69876</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-02-14T14:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382172#M69878</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/716583"&gt;@EddX&lt;/a&gt;&amp;nbsp;after you run the SearchCursor portion of code, try executing the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;del oRows&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 14 Feb 2024 14:07:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382172#M69878</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-02-14T14:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382557#M69883</link>
      <description>&lt;P&gt;I can set up an editor class (&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/3.1/arcpy/data-access/editor.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/3.1/arcpy/data-access/editor.htm&lt;/A&gt;&amp;nbsp;this?)&amp;nbsp;&lt;BR /&gt;will&amp;nbsp;startEditing allow me to override the schema lock that exists and be able to use UpdateCursor? Reading the documentation in the link above, to my understanding the edit session is automatically handled within a with statement when using cursors, is this correct?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And for field calculator, is there a way to do this via arcpy? is it this?&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 22:37:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382557#M69883</guid>
      <dc:creator>EddX</dc:creator>
      <dc:date>2024-02-14T22:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382573#M69884</link>
      <description>&lt;P&gt;Hello, I've added this as requested. The script still hangs at the UpdateCursor, and the schema lock still exists. Do you think the schema lock is causing the issue?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 22:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382573#M69884</guid>
      <dc:creator>EddX</dc:creator>
      <dc:date>2024-02-14T22:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382623#M69885</link>
      <description>&lt;P&gt;Hey so out of curiosity:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;How many records does your table have?&lt;BR /&gt;and&lt;/LI&gt;&lt;LI&gt;Do you have the attribute table open when running this?&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 15 Feb 2024 00:14:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382623#M69885</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-02-15T00:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382660#M69886</link>
      <description>&lt;P&gt;200,000+&lt;BR /&gt;Yes, the attribute table is open when I run this.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Unfortunately part of the process of this script requires human involvement (checking) and hence the script is run via the python terminal within ArcPro with the table open/loaded. Somehow this worked previously within ArcMap. I read somewhere that ArcPro has much stricter schema locking that ArcMap.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I can share the script if that helps?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you for your help so far, I appreciate it.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 03:44:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382660#M69886</guid>
      <dc:creator>EddX</dc:creator>
      <dc:date>2024-02-15T03:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382793#M69888</link>
      <description>&lt;P&gt;So, not sure if this causing it or not, but the reason I asked is &lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/please-change-attribute-table-open-constitutes-a/idi-p/1360990" target="_blank" rel="noopener"&gt;because&lt;/A&gt; of &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/pro-3-1-3-running-an-update-cursor-on-a-feature/m-p/1339224" target="_blank" rel="noopener"&gt;this&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Granted, it was happening in a Python toolbox and not in the python window, but the short of it was having running an update cursor on a table with 200+ records caused a lock error if the table was open while the tool was running.&lt;/P&gt;&lt;P&gt;Shot in the dark, but maybe try closing the table while running the script and then reopening it to check?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 14:06:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382793#M69888</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-02-15T14:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382796#M69889</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/716583"&gt;@EddX&lt;/a&gt;&amp;nbsp;having the table open will cause a lock.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 14:11:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1382796#M69889</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-02-15T14:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python in ArcPro - How To arcpy.da.UpdateCursor on a SDE which is open/schema locked</title>
      <link>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1383707#M69904</link>
      <description>&lt;P&gt;Both the InsertCursor and the UpdateCursor require an Editing Session to be created and started. You can only create a single InsertCursor or UpdateCursor in any single editing session. I typically run my updates to catch any errors during the update and drops all edits if an exception is thrown.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Also, you do not need to check for a schema lock on the dataset. A schema lock will not prevent you from editing the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;arcpy&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;pathlib &lt;SPAN&gt;import &lt;/SPAN&gt;Path&lt;BR /&gt;&lt;BR /&gt;connection_path: &lt;SPAN&gt;str &lt;/SPAN&gt;= &lt;SPAN&gt;r'path\to\geodatabase\connection\file.sde'&lt;BR /&gt;&lt;/SPAN&gt;table_name: &lt;SPAN&gt;str &lt;/SPAN&gt;= &lt;SPAN&gt;'Cadaster'&lt;BR /&gt;&lt;/SPAN&gt;table_path: &lt;SPAN&gt;str &lt;/SPAN&gt;= [&lt;SPAN&gt;str&lt;/SPAN&gt;(Path(dirpath) / filename) &lt;BR /&gt;                   &lt;SPAN&gt;for &lt;/SPAN&gt;dirpath&lt;SPAN&gt;, &lt;/SPAN&gt;_&lt;SPAN&gt;, &lt;/SPAN&gt;filenames &lt;SPAN&gt;in &lt;/SPAN&gt;arcpy.da.Walk(connection_path)&lt;BR /&gt;                   &lt;SPAN&gt;for &lt;/SPAN&gt;filename &lt;SPAN&gt;in &lt;/SPAN&gt;filenames&lt;BR /&gt;                   &lt;SPAN&gt;if &lt;/SPAN&gt;filename.split(&lt;SPAN&gt;'.'&lt;/SPAN&gt;)[-&lt;SPAN&gt;1&lt;/SPAN&gt;] == table_name].pop()&lt;BR /&gt;&lt;BR /&gt;edit_session: arcpy.da.Editor = arcpy.da.Editor(connection_path)&lt;BR /&gt;edit_session.startEditing(&lt;SPAN&gt;True, True&lt;/SPAN&gt;)&lt;BR /&gt;edit_session.startOperation()&lt;BR /&gt;save_edits: &lt;SPAN&gt;bool &lt;/SPAN&gt;= &lt;SPAN&gt;True&lt;BR /&gt;&lt;/SPAN&gt;total_update_count: &lt;SPAN&gt;int &lt;/SPAN&gt;= &lt;SPAN&gt;0&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;:&lt;BR /&gt;    &lt;SPAN&gt;with &lt;/SPAN&gt;arcpy.da.UpdateCursor(table_name&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'Z'&lt;/SPAN&gt;) &lt;SPAN&gt;as &lt;/SPAN&gt;update_cursor:&lt;BR /&gt;        &lt;SPAN&gt;for &lt;/SPAN&gt;current_row &lt;SPAN&gt;in &lt;/SPAN&gt;update_cursor:&lt;BR /&gt;            updated_row = current_row&lt;BR /&gt;            &lt;SPAN&gt;# do what ever you need to alter the row&lt;BR /&gt;&lt;/SPAN&gt;            update_cursor.updateRow(updated_row)&lt;BR /&gt;            total_update_count += &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;Exception &lt;/SPAN&gt;&lt;SPAN&gt;as &lt;/SPAN&gt;e:&lt;BR /&gt;    save_edits = &lt;SPAN&gt;False&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    raise &lt;/SPAN&gt;e&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;finally&lt;/SPAN&gt;:&lt;BR /&gt;    &lt;SPAN&gt;# Stop and save the editing session&lt;BR /&gt;&lt;/SPAN&gt;    edit_session.stopOperation()&lt;BR /&gt;    edit_session.stopEditing(save_edits)&lt;BR /&gt;    &lt;SPAN&gt;del &lt;/SPAN&gt;edit_session&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2024 03:17:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-in-arcpro-how-to-arcpy-da-updatecursor-on-a/m-p/1383707#M69904</guid>
      <dc:creator>matkowm_aw</dc:creator>
      <dc:date>2024-02-17T03:17:57Z</dc:date>
    </item>
  </channel>
</rss>

