<?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: Update shape with arcpy.management.CalculateField SQL expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661505#M74822</link>
    <description>&lt;P&gt;If you don't initiate a transaction, there can be 'pending edits' because another part of your code grabbed a lock and never released it. The error you're getting seems to be some uncleared lock on the table.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Oct 2025 19:28:23 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2025-10-28T19:28:23Z</dc:date>
    <item>
      <title>Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660646#M74814</link>
      <description>&lt;P&gt;I have a local mobile geodatabase with a polyline featureclass (with Z and M values). The database has loaded&amp;nbsp;&lt;SPAN&gt;stgeometry_sqlite.dll extension and&amp;nbsp;&lt;SPAN class=""&gt;OGC Tables created.&lt;/SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I am trying to update SHAPE values with&amp;nbsp;arcpy.management.CalculateField method and SQL expression. The function to build expression:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def make_case_expression(oid_field, oid_to_wkt, wkid):
    """
    oid_field - string, e.g. 'OBJECTID'
    oids_to_wkt - dict, with structure: {int OBJECTID: text WKT shape}
    wkid - int, WKID number, e.g. 3500
    """
    lines = ["CASE"]
    for oid, wkt in oid_to_wkt.items():
        lines.append(f"  WHEN {oid_field} = {int(oid)} THEN st_geometry('{wkt}', {wkid})")
    lines.append("  ELSE SHAPE")
    lines.append("END")
    return "\n".join(lines)&lt;/LI-CODE&gt;&lt;P&gt;It creates an expression like (fake coords):&lt;/P&gt;&lt;PRE&gt;"CASE\n  WHEN OBJECTID = 12 THEN st_geometry('MULTILINESTRING Z ((6250000.0 1956000.0 0, 6250800.0 1956000.0 0))', 3500)\n  WHEN OBJECTID = 13 THEN st_geometry('MULTILINESTRING Z ((6250900.0 1956000.0 0, 6250800.0 1956000.0 0))', 3500)\n ELSE SHAPE\nEND"&lt;/PRE&gt;&lt;P&gt;Then I run function to Calculate Field:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(
    in_table=path_lines,
    field="SHAPE",
    expression=exp,
    expression_type="SQL"
)&lt;/LI-CODE&gt;&lt;P&gt;...and catch an error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py:8504, in CalculateField(in_table, field, expression, expression_type, code_block, field_type, enforce_domains)
   8500 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   8502 try:
   8503     retval = convertArcObjectToPythonObject(
-&amp;gt; 8504         gp.CalculateField_management(
   8505             *gp_fixargs(
   8506                 (in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True
   8507             )
   8508         )
   8509     )
   8510     return retval
   8511 except Exception as e:

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py:533, in Geoprocessor.__getattr__.&amp;lt;locals&amp;gt;.&amp;lt;lambda&amp;gt;(*args)
    531 val = getattr(self._gp, attr)
    532 if callable(val):
--&amp;gt; 533     return lambda *args: val(*gp_fixargs(args, True))
    534 else:
    535     return convertArcObjectToPythonObject(val)

ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
User transaction in progress -- operation not allowed
Failed to execute (CalculateField).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any ideas&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2025 18:52:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660646#M74814</guid>
      <dc:creator>EugeneSosnin_GSI</dc:creator>
      <dc:date>2025-10-24T18:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660664#M74815</link>
      <description>&lt;P&gt;any pending edits on the file that haven't been saved?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2025 19:20:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660664#M74815</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-10-24T19:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660668#M74816</link>
      <description>&lt;P&gt;No pending edits&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2025 19:23:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1660668#M74816</guid>
      <dc:creator>EugeneSosnin_GSI</dc:creator>
      <dc:date>2025-10-24T19:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661389#M74820</link>
      <description>&lt;P&gt;Wrap your calculation in an edit session.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

# Start an edit session
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, True)  # False for non-versioned, True for multiuser

try:
    edit.startOperation()
    
    arcpy.management.CalculateField(
        in_table=path_lines,
        field="SHAPE",
        expression=exp,
        expression_type="SQL"
    )
    
    edit.stopOperation()
    edit.stopEditing(True)  # True to save changes
    
except Exception as e:
    edit.stopOperation()
    edit.stopEditing(False)  # False to discard changes
    raise e&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&amp;nbsp;Instead of CalculateField, use an UpdateCursor&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.da.UpdateCursor(feature_class, ["OBJECTID", "SHAPE@"]) as cursor:
    for oid, shape in cursor:
        if oid in oid_to_wkt:
            geom = arcpy.FromWKT(oid_to_wkt[oid], arcpy.SpatialReference(wkid))
            cursor.updateRow((oid, geom))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2025 16:09:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661389#M74820</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-10-28T16:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661505#M74822</link>
      <description>&lt;P&gt;If you don't initiate a transaction, there can be 'pending edits' because another part of your code grabbed a lock and never released it. The error you're getting seems to be some uncleared lock on the table.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2025 19:28:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661505#M74822</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-10-28T19:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661604#M74823</link>
      <description>&lt;P&gt;CalculateField operation is not allowed during Editing operation. There is no lock I am sure 100%. PS. if there's lock it returns error: 464.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2025 00:16:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661604#M74823</guid>
      <dc:creator>EugeneSosnin_GSI</dc:creator>
      <dc:date>2025-10-29T00:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Update shape with arcpy.management.CalculateField SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661606#M74824</link>
      <description>&lt;P&gt;Sadly to say, but your code is wrong.&amp;nbsp;CalculateField operation with SQL parameter is not allowed during Editing operation.&lt;/P&gt;&lt;P&gt;There is a reason, I tried to use CalculateField with SQL parameter, as it's more performative. Current solution I have: split edits into chunks and run UpdateCursor. But I am still interested in CalculateField with SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also your code would be better (more Pythonic) if formatted:&lt;/P&gt;&lt;P&gt;with arcpy.da.Editor(workspace):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; with arcpy.da.UpdateCursor(path, fields, qry) as cur:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for row in cur:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;edits&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/P&gt;&lt;P&gt;If there's an error, edits won't be saved.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2025 20:55:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-shape-with-arcpy-management-calculatefield/m-p/1661606#M74824</guid>
      <dc:creator>EugeneSosnin_GSI</dc:creator>
      <dc:date>2025-11-26T20:55:33Z</dc:date>
    </item>
  </channel>
</rss>

