<?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 arcpy.da.InsertCursor returning 'RuntimeError' error message in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006075#M59189</link>
    <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Gday everyone&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I've hit a strange problem with a Python process I'm trying to build that uses a couple of arcpy.da cursors.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;The way the process is structured, firstly I am using a arcpy.da.InsertCursor to add rows to a feature class based on logic from a prior step. The process is running fine up until this point.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I then need to call an arcpy.da.UpdateCursor on the same feature class, and this is where I'm striking the "Runtime error - cannot open file feature_class_name".&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I thought maybe it was due to the cursor from the InsertCursor object still being live, so I've refactored the script to explicitly delete the object, with no luck. I also thought there may be a race condition where the UpdateCursor was being called before the InsertCursor object was deleted, so I explicitly built in a 5 second pause. No success either.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I'm 100% certain I have the syntax right (but have double and triple checked) - and I'm at a bit of a loss with this issue.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Has anyone got any suggestions that may send me in the right direction?&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;On ArcMap 10.7.1 and code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;hashes_source = []
with arcpy.da.SearchCursor(source_ch_data,fieldlist[0:-4]) as cur:
    for row in cur:
        sourcehash = get_hash(row)
        hashes_source.append(sourcehash)
        if sourcehash not in hashes:
            print "Inserting row for",sourcehash
            icur = arcpy.da.InsertCursor("PRELIMINARY_REPORTS_ALL",fieldlist)
            icur.insertRow(row+("Y",last_update_dto,None,sourcehash))
            del icur

time.sleep(5)

# process runs ok to this point, fails where UpdateCursor is called below
# error message below:

'''
Traceback (most recent call last):
  File "C:\folder_location\change_detection.py", line 101, in &amp;lt;module&amp;gt;
    with arcpy.da.UpdateCursor("PRELIMINARY_RECORDS_ALL",["CURRENT_RECORD_YN","RECORD_RETIRED_DT","HASH_SHA256_HEX"]) as cur:
RuntimeError: cannot open 'PRELIMINARY_RECORDS_ALL'
'''

# iterate through destination table
# if hash not in source table, retire the record
with arcpy.da.UpdateCursor("PRELIMINARY_RECORDS_ALL",["CURRENT_RECORD_YN","RECORD_RETIRED_DT","HASH_SHA256_HEX"]) as cur:
    for row in cur:
        if row[2] not in hashes_source:
            print "Retiring record",row[2]
            row[0] = "N"
            row[1] = last_update_dto
            cur.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 02 Dec 2020 01:42:54 GMT</pubDate>
    <dc:creator>AnthonyCheesman1</dc:creator>
    <dc:date>2020-12-02T01:42:54Z</dc:date>
    <item>
      <title>arcpy.da.InsertCursor returning 'RuntimeError' error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006075#M59189</link>
      <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Gday everyone&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I've hit a strange problem with a Python process I'm trying to build that uses a couple of arcpy.da cursors.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;The way the process is structured, firstly I am using a arcpy.da.InsertCursor to add rows to a feature class based on logic from a prior step. The process is running fine up until this point.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I then need to call an arcpy.da.UpdateCursor on the same feature class, and this is where I'm striking the "Runtime error - cannot open file feature_class_name".&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I thought maybe it was due to the cursor from the InsertCursor object still being live, so I've refactored the script to explicitly delete the object, with no luck. I also thought there may be a race condition where the UpdateCursor was being called before the InsertCursor object was deleted, so I explicitly built in a 5 second pause. No success either.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I'm 100% certain I have the syntax right (but have double and triple checked) - and I'm at a bit of a loss with this issue.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Has anyone got any suggestions that may send me in the right direction?&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;On ArcMap 10.7.1 and code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;hashes_source = []
with arcpy.da.SearchCursor(source_ch_data,fieldlist[0:-4]) as cur:
    for row in cur:
        sourcehash = get_hash(row)
        hashes_source.append(sourcehash)
        if sourcehash not in hashes:
            print "Inserting row for",sourcehash
            icur = arcpy.da.InsertCursor("PRELIMINARY_REPORTS_ALL",fieldlist)
            icur.insertRow(row+("Y",last_update_dto,None,sourcehash))
            del icur

time.sleep(5)

# process runs ok to this point, fails where UpdateCursor is called below
# error message below:

'''
Traceback (most recent call last):
  File "C:\folder_location\change_detection.py", line 101, in &amp;lt;module&amp;gt;
    with arcpy.da.UpdateCursor("PRELIMINARY_RECORDS_ALL",["CURRENT_RECORD_YN","RECORD_RETIRED_DT","HASH_SHA256_HEX"]) as cur:
RuntimeError: cannot open 'PRELIMINARY_RECORDS_ALL'
'''

# iterate through destination table
# if hash not in source table, retire the record
with arcpy.da.UpdateCursor("PRELIMINARY_RECORDS_ALL",["CURRENT_RECORD_YN","RECORD_RETIRED_DT","HASH_SHA256_HEX"]) as cur:
    for row in cur:
        if row[2] not in hashes_source:
            print "Retiring record",row[2]
            row[0] = "N"
            row[1] = last_update_dto
            cur.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 01:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006075#M59189</guid>
      <dc:creator>AnthonyCheesman1</dc:creator>
      <dc:date>2020-12-02T01:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.InsertCursor returning 'RuntimeError' error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006081#M59191</link>
      <description>&lt;P&gt;Could you please provide the tables you are trying to edit/update.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Spatial enable dataframes&amp;nbsp; could achieve the same and I have found them much easier and a way of the future I think&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 02:47:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006081#M59191</guid>
      <dc:creator>wwnde</dc:creator>
      <dc:date>2020-12-02T02:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.InsertCursor returning 'RuntimeError' error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006099#M59193</link>
      <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Issue found, and it's **bleep** embarrassing I must admit - I stuffed up the name of the feature class. And despite double, triple and quadruple checking - it still slipped through the cracks.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;The correct name was PRELIMINARY_REPORTS_ALL, but I was trying to open a cursor on PRELIMINARY_RECORDS_ALL (which doesn't exist).&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Problem solved...&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 05:24:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-insertcursor-returning-runtimeerror-error/m-p/1006099#M59193</guid>
      <dc:creator>AnthonyCheesman1</dc:creator>
      <dc:date>2020-12-02T05:24:11Z</dc:date>
    </item>
  </channel>
</rss>

