<?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 Append in Python is suddenly requiring an edit session? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684061#M75110</link>
    <description>&lt;P&gt;We added this and confirmed all looks well until the failure point - but then the script fails at the same point so I think the message is valid.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Feb 2026 17:50:11 GMT</pubDate>
    <dc:creator>Sean_Gambrel</dc:creator>
    <dc:date>2026-02-12T17:50:11Z</dc:date>
    <item>
      <title>Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683712#M75103</link>
      <description>&lt;P&gt;Hello,&amp;nbsp; A colleague and I have developed some python that, among other things, joins a table to a feature class and then copies specific features from there into a different, existing feature class.&amp;nbsp; This has run smoothly for over a year.&amp;nbsp; Suddenly the script is failing, stating that an edit session is needed to run the Append tool - which doesn't seem right - and anyway, our attempts at adding an edit session into the script causes the whole thing to fail from the get-go.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;A month or so ago there was a recent change to the database that the table comes from, but we've accommodated that change.&amp;nbsp; Nothing has changed on the gis-side in any way - feature classes, locations, etc.&amp;nbsp; Nothing has changed within our organizations enterprise / software that should affect this as far as I'm aware.&amp;nbsp; Any idea what's going on and how to repair this issue?&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't attach the full error message but the most pertinent part seems to be this:&amp;nbsp; &lt;EM&gt;"arcgisscripting.ExecuteError:&amp;nbsp; ERROR 160250: Objects in this class cannot be updated outside an edit session.&amp;nbsp; Failed to execute (Append)"&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Here's what I think is the pertinent section of code, though it hasn't been changed:&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;survey_plat = r'V:\\gislu\\_DatabaseConnection\\editgis1.lu.user.dc.sde\\lu.LU.SURV_SurveyPlat'&lt;BR /&gt;count_pre_append = int(arcpy.management.GetCount(survey_plat)[0])&lt;/P&gt;&lt;P&gt;results = arcpy.management.Append(&lt;BR /&gt;inputs=surveys_added,&lt;BR /&gt;target=survey_plat,&lt;BR /&gt;schema_type='NO_TEST',&lt;BR /&gt;field_mapping="SURVEY_ID \"SURVEY_ID\" true true false 12 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,survey_id,0,7999;SURVEY_TYP \"SURVEY_TYP\" true true false 25 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,survey_type,0,7999;SURVEY_DES \"SURVEY_DES\" true true false 254 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,survey_descr,0,7999;SURVEY_YR \"SURVEY_YR\" true true false 4 Long 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,survey_year,-1,-1;PLSS_COORD \"PLSS_COORD\" true true false 2 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,PLSS_COORD,0,7999;LINK \"LINK\" true true false 256 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,link,0,7999;PARCEL_NO \"PARCEL_NO\" true true false 12 Text 0 0,First,#,V:\\prjlu\\SurveyPlats\\PlatProcessingAutomation\\SurveyProcessing.gdb\\SurveysAdded,parcel_id,0,7999"&lt;BR /&gt;)&lt;BR /&gt;print(results)&lt;BR /&gt;print(arcpy.GetMessages())&lt;/P&gt;&lt;P&gt;count_post_append = int(arcpy.management.GetCount(survey_plat)[0])&lt;BR /&gt;count_delta = count_post_append - count_pre_append&lt;BR /&gt;print(f'{count_delta} records appended')&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2026 17:12:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683712#M75103</guid>
      <dc:creator>Sean_Gambrel</dc:creator>
      <dc:date>2026-02-11T17:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683743#M75104</link>
      <description>&lt;P&gt;Can you print out&amp;nbsp;&lt;SPAN&gt;count_pre_append to see if the script is evaluating that variable correctly?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Maybe its a misleading error message, so I would put in additional print statements to make sure variables are being evaluated correctly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2026 18:42:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683743#M75104</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2026-02-11T18:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683751#M75105</link>
      <description>&lt;P&gt;This isn't super helpful, but can confirm stuff like this happens. I had a script that worked just fine on day 1 and then on day 2 required an edit session when I was using an update cursor. Hadn't even changed it yet.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2026 19:13:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683751#M75105</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2026-02-11T19:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683779#M75107</link>
      <description>&lt;P&gt;Did&amp;nbsp;something changed on the database side?&amp;nbsp;Register As Versioned or&amp;nbsp;enabled branch versioning. This has happened to me for no reason as well, but I also know if something on the database has changed it can trig it.&lt;/P&gt;&lt;P&gt;Try adding,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;workspace = r"V:\gislu\_DatabaseConnection\editgis1.lu.user.dc.sde"

edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()

arcpy.management.Append(
    inputs=surveys_added,
    target=survey_plat,
    schema_type="NO_TEST",
    field_mapping=...
)

edit.stopOperation()
edit.stopEditing(True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Feb 2026 19:55:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683779#M75107</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2026-02-11T19:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683898#M75108</link>
      <description>&lt;P&gt;The Append function will hook into existing edit sessions if run in a map context. That behavior can be a bit odd when you then run the same tool with no active edit session&lt;/P&gt;&lt;P&gt;It's best practice to use the `with arcpy.da.Editor` context block when doing any write operations since it'll prevent undefined behavior when an edit session can't be found, and will fail gracefully if there's an issue during the transaction/edit block.&lt;/P&gt;&lt;P&gt;Additionally, using an edit context with arcpy.da.UpdateCursor can be a lot more informative since Append just kinda consumes a lot of row level messages. doing it with UpdateCursor lets you handle bad data (e.g. a single input row that has a text field of length of 1000 being appended to a target field of length 255).&lt;/P&gt;&lt;P&gt;Some others mentioned how to use the edit session here, but I would absolutely make sure to use the `with Editor as edit` pattern, since an exception being raised before editor.stopEditing is called will leave your database with an open edit lock.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's your script using Edit sessions and an InsertCursor&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.da import InsertCursor, SearchCursor, Editor

# Target Workspace
gdb = r'V:\prjlu\SurveyPlats\PlatProcessingAutomation\SurveyProcessing.gdb'
new_survey = 'SurveysAdded'

sde = r'V:\gislu\_DatabaseConnection\editgis1.lu.user.dc.sde'
survey_plat = 'lu.LU.SURV_SurveyPlat'

# Map new_survey -&amp;gt; survey_plat
field_map = {
    'SURVEY_ID': 'survey_id',
    'SURVEY_TYP': 'survey_typ',
    'SURVEY_DES': 'survey_descr',
    'SURVEY_YR': 'survey_year',
    'PLSS_COORD': 'PLSS_COORD',
    'LINK': 'link',
    'PARCEL_NO': 'parcel_id',
}

# Use these in the cursors
source_fields = list(field_map.keys())
target_fields = list(field_map.values())

new_rows = list(SearchCursor(new_survey, source_fields))

# You can use multiple context managers in one with block
with Editor(sde), InsertCursor(survey_plat, target_fields) as cur:
    for row in new_rows:
        cur.insertRow(row)
print(f'{len(new_rows)} records appended')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 05:53:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683898#M75108</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2026-02-12T05:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683968#M75109</link>
      <description>&lt;P&gt;Another reason to use an update cursor is that it's MILES faster than Append().&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 14:30:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1683968#M75109</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2026-02-12T14:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684061#M75110</link>
      <description>&lt;P&gt;We added this and confirmed all looks well until the failure point - but then the script fails at the same point so I think the message is valid.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 17:50:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684061#M75110</guid>
      <dc:creator>Sean_Gambrel</dc:creator>
      <dc:date>2026-02-12T17:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684062#M75111</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp; Gave this a shot but no change in behavior.&amp;nbsp; I think we may have a solution below though...&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 17:51:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684062#M75111</guid>
      <dc:creator>Sean_Gambrel</dc:creator>
      <dc:date>2026-02-12T17:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684066#M75112</link>
      <description>&lt;P&gt;Additionally, this style plays way better with version control since the field map isn't just a giant one line string that's hundreds of characters long.&lt;/P&gt;&lt;P&gt;Now you just update the mapping dictionary and can see exactly what changed with a commit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Here's a more robust version of the above code that supports arbitrary mappings using lambda expressions (You can also just define normal functions and use those. That's a much better idea):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from collections.abc import Callable, Generator, Sequence
from typing import Any
from arcpy.da import InsertCursor, SearchCursor, Editor


type FieldCalc = Callable[[tuple[Any, ...]], Any]
type FieldNames = Sequence[str]
type FieldMap = dict[str, tuple[FieldCalc, FieldNames] | str]


def process_map(f_map: FieldMap) -&amp;gt; tuple[list[str], list[str]]:
    """Consume a field mapping dictionary and return all fields participating on both sides
    
    Note: Returned values are in order (source, target)
    """
    target_fields = list(f_map.keys())
    source_fields: list[str] = []
    for mapping in f_map.values():
        if isinstance(mapping, tuple):
            # mapping has a functional component
            _, fields = mapping
            source_fields.extend(fields)
        else:
            # mapping is direct
            source_fields.append(mapping)
    return source_fields, target_fields


# Map the row values to field names
def as_dict(cur: SearchCursor) -&amp;gt; Generator[dict[str, Any]]:
    """Make cursor rows dictionaries"""
    for row in cur:
        yield dict(zip(cur.fields, row))


def calculate_row(target_fields: Sequence[str], source_row: dict[str, Any], field_map: FieldMap) -&amp;gt; list[Any]:
    """Apply a Row-Wise functional/direct map to a Cursor
    
    Note: Returned list will match the field order supplied by `target_fields`
    """
    row_vals: list[Any] = []
    for field in target_fields:
        mapping = field_map.get(field)
        if mapping is None:
            raise ValueError(f'Field {field} is not mapped!')
        if isinstance(mapping, tuple):
            # Functional Map
            func, source_fields = mapping
            row_vals.append(func(tuple(source_row[f] for f in source_fields)))
        else:
            # Direct Map
            row_vals.append(source_row[mapping])
    return row_vals

def main():
    # Target Workspace
    new_survey = 'SurveysAdded'

    sde = r'V:\gislu\_DatabaseConnection\editgis1.lu.user.dc.sde'
    survey_plat = 'lu.LU.SURV_SurveyPlat'
    field_map: FieldMap = {
        'survey_id': (lambda vs: ';'.join(map(str, vs)), ['SURVEY_ID1', 'SURVEY_ID2']),
        'survey_typ': (lambda vs: ([v for v in vs if v]+[None]).pop(0), ['SURVEY_TYP', 'ALT_TYP']),
        'survey_descr': 'SURVEY_DES',
        'survey_year': 'SURVEY_YR',
        'PLSS_COORD': (lambda vs: vs[0][:6], ['PLSS_COORD']), # Truncate
        'link': (lambda vs: str(vs[0]).replace('http', 'https'), ['LINK']),
        'parcel_id': 'PARCEL_NO',
    }
    source_fields, target_fields = process_map(field_map)
    new_rows = list(as_dict(SearchCursor(new_survey, source_fields)))
    
    # You can use multiple context managers in one with block
    with Editor(sde), InsertCursor(survey_plat, target_fields) as cur:
        for row in new_rows:
            cur.insertRow(calculate_row(target_fields, row, field_map))
    print(f'{len(new_rows)} records appended')
    
    
if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit 2:&lt;/P&gt;&lt;P&gt;Here's a more reasonable way to do the functional mappings:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...

def join(vals: tuple[Any, ...]) -&amp;gt; str:
    return ';'.join(map(str, vals))

def first(vals: tuple[Any, ...]) -&amp;gt; Any:
    return next(filter(bool, vals), None)

def truncate(vals: tuple[str]) -&amp;gt; str:
    return vals[0][:6]

def make_https(vals: tuple[str]) -&amp;gt; str:
    return vals[0].replace('http', 'https')

field_map: FieldMap = {
    'survey_id': (join, ['SURVEY_ID1', 'SURVEY_ID2']),
    'survey_typ': (first, ['SURVEY_TYP', 'ALT_TYP']),
    'survey_descr': 'SURVEY_DES',
    'survey_year': 'SURVEY_YR',
    'PLSS_COORD': (truncate, ['PLSS_COORD']), # Truncate
    'link': (make_https, ['LINK']),
    'parcel_id': 'PARCEL_NO',
}

...&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 12 Feb 2026 19:11:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684066#M75112</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2026-02-12T19:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684456#M75115</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/971307"&gt;@Sean_Gambrel&lt;/a&gt;&amp;nbsp;did any of this work for you?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Feb 2026 22:23:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684456#M75115</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2026-02-13T22:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684739#M75117</link>
      <description>&lt;P&gt;Nothing so far.&amp;nbsp; But this is kind of a side project so we haven't been working on it non-stop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We tried the code you posted Wednesday and we got errors on the import line, assuming maybe something with the InsertCursor? and running it crashes straight out of the gate, predictably I suppose.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We haven't tried your suggestions from Thursday, but hoping we can try again today.&lt;BR /&gt;&lt;BR /&gt;Really appreciate your help and commitment here!!!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2026 16:13:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684739#M75117</guid>
      <dc:creator>Sean_Gambrel</dc:creator>
      <dc:date>2026-02-17T16:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Append in Python is suddenly requiring an edit session?</title>
      <link>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684762#M75118</link>
      <description>&lt;P&gt;hmm, collections.abc is a newer thing in python. I added those imports for typing. You can also move those into the from typing ... import block if you're using Python &amp;lt; 3.13&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2026 17:11:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-append-in-python-is-suddenly-requiring-an/m-p/1684762#M75118</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2026-02-17T17:11:06Z</dc:date>
    </item>
  </channel>
</rss>

