<?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 Database is stale after deleted table data using Pro UI and fetching using SearchCursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635190#M74509</link>
    <description>&lt;P&gt;`&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;da&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SearchCursor` is returning unpredicable results.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have an empty table in pro. I just deleted it and saved it, so I know it's empty.&amp;nbsp;&lt;BR /&gt;When I then `&lt;SPAN&gt;SearchCursor` on that table it returns results! But the table is empty!&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cur = arcpy.da.SearchCursor(full_table_path, field_names)
for c in cur:
    print(c)&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I wanted to use this function to check for duplicates &lt;EM&gt;before&lt;/EM&gt; inserting, but it se&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;ems highly unstable. Is there any way to make it pick up recent changes?&lt;BR /&gt;Whatever the issue, if the table is not actually empty but just shows empty, or if it's the function, I just need it to work accurately.&lt;BR /&gt;It's a file table, so maybe this is why?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jul 2025 18:03:16 GMT</pubDate>
    <dc:creator>chris_del101</dc:creator>
    <dc:date>2025-07-23T18:03:16Z</dc:date>
    <item>
      <title>Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635190#M74509</link>
      <description>&lt;P&gt;`&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;da&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SearchCursor` is returning unpredicable results.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have an empty table in pro. I just deleted it and saved it, so I know it's empty.&amp;nbsp;&lt;BR /&gt;When I then `&lt;SPAN&gt;SearchCursor` on that table it returns results! But the table is empty!&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cur = arcpy.da.SearchCursor(full_table_path, field_names)
for c in cur:
    print(c)&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I wanted to use this function to check for duplicates &lt;EM&gt;before&lt;/EM&gt; inserting, but it se&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;ems highly unstable. Is there any way to make it pick up recent changes?&lt;BR /&gt;Whatever the issue, if the table is not actually empty but just shows empty, or if it's the function, I just need it to work accurately.&lt;BR /&gt;It's a file table, so maybe this is why?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 18:03:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635190#M74509</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-07-23T18:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635208#M74510</link>
      <description>&lt;P&gt;Try this, always use the cursor within a WITH&amp;nbsp;statement to ensure proper cleanup.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class=""&gt;.&lt;/SPAN&gt;da&lt;SPAN class=""&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class=""&gt;(&lt;/SPAN&gt;full_table_path&lt;SPAN class=""&gt;,&lt;/SPAN&gt; field_names&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; cur&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; cur&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
        &lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;row&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 21:31:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635208#M74510</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-07-22T21:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635285#M74512</link>
      <description>&lt;P&gt;As Tony said, you always want to use the context manager protocol when it's implemented (with Foo() as bar : ...).&lt;/P&gt;&lt;P&gt;Cursors will maintain a lock on the table until they're deleted (with del) which happens automatically once you exit the with block.&lt;/P&gt;&lt;P&gt;They can also be confusing if you are using different inputs. Say a layer with a selection or a definition query instead of a raw table/feature resource.&lt;/P&gt;&lt;P&gt;Cursors that are passed a layer object with implicitly respect any selections and queries you have on that layer, but if you pass it the raw data source, they won't respect those selections and queries.&lt;/P&gt;&lt;P&gt;It's good practice to be very clear what you're passing into the Cursor. I usually do this by extracting the selection set from the layer and populating the "where_clause" argument of the initializer with a SQL statement "OBJECTID IN (&amp;lt;selection_set&amp;gt;)" as this lets me more easily debug what the Cursor is seeing.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 03:43:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635285#M74512</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-23T03:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635375#M74513</link>
      <description>&lt;P&gt;I agree with both &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;and&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;. Using the 'with' statement is general best practice when it comes to using any cursor. Like&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp;said, the 'with' statement ensures the object deletes after the cursor finishes executing. The other thing you can include are break conditions to stop the execution earlier or pass conditions to skip over rows.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 13:21:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635375#M74513</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-07-23T13:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635400#M74514</link>
      <description>&lt;P&gt;I'm gonna make a "Comprehending Cursors in Context" Blog post soon to try and document more advanced Cursor patterns. My favorite way to use a SearchCursor is in a comprehension because it immediately de-structures the data into whatever Python object you want and doesn't store a ref so it's deleted as soon as the comprehension runs.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 13:20:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635400#M74514</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-23T13:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635468#M74515</link>
      <description>&lt;P&gt;I think that is a great idea. Let me know if you are open to making it a joint blog or allowing some input from others to add to it. I often use the comprehension to create dictionaries while simultaneously having another dictionary to field map different schemas on the fly. That significantly reduces the amount of effort when it comes to migrating data or running specific analyses.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 14:51:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635468#M74515</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-07-23T14:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635477#M74516</link>
      <description>&lt;P&gt;I'll set up a repo on GitHub, DM me your username and I'll add you as a collaborator!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 15:10:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635477#M74516</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-23T15:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635649#M74520</link>
      <description>&lt;P&gt;Note: The syntax I used was for brevity. I'm using `with` already, so this is not the issue.&amp;nbsp;Apologies for the extra noise. I think I'll change the post title since this is not really a SearchCursor issue (I think)&lt;/P&gt;&lt;P&gt;This real issue, I've confirmed, is that the database state is stale. It's not a SearchCursor specific issue but still...&lt;/P&gt;&lt;P&gt;1.In Pro I select all in the database table and click delete, and confirm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chris_del101_0-1753281457081.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137022i94EE116CCAAA93D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chris_del101_0-1753281457081.png" alt="chris_del101_0-1753281457081.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2. Save(?). It saves &lt;EM&gt;something,&lt;/EM&gt;&amp;nbsp;I am prompted, but not sure what (is saved)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here a loading bar comes up saying "saving" for a second (not shown). The table is empty.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chris_del101_2-1753281628666.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137025i4B3A1A7B6CFCC4C5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chris_del101_2-1753281628666.png" alt="chris_del101_2-1753281628666.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;FYI only, as closing like this refreshes the data: but I don't want to have to restart.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;When closing instead I get two prompts&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chris_del101_3-1753282844736.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137026i5FDA050F26BD9189/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chris_del101_3-1753282844736.png" alt="chris_del101_3-1753282844736.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And then&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chris_del101_4-1753282854133.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137027iC6505263F1753E95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chris_del101_4-1753282854133.png" alt="chris_del101_4-1753282854133.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Pro would now close - &lt;/EM&gt;in theory. We are trying not to close it every time.&lt;/P&gt;&lt;P&gt;3. Run Query - Data is returned!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;records = []
full_table_path = f"{self.sde_path}\\{table_name}"
with arcpy.da.SearchCursor(full_table_path, field_names) as cursor:
                for row in cursor:
                         records.append(row)
                return records​&lt;/LI-CODE&gt;&lt;P&gt;This is same item at the top of the list in the first screen shot.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;('Total Sample Weight', 'Kg', 'Sample Weight Total: The total mass of the sample before processing.', '32', 32.0, '1111 ', 'gggg')&lt;/LI-CODE&gt;&lt;P&gt;These inaccurate results should not happen. Is there anyway to make the empty state&amp;nbsp;proliferate?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 18:06:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635649#M74520</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-07-23T18:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635654#M74521</link>
      <description>&lt;P&gt;Sound like you might need to start an edit session to save when you delete features before you use the search cursor?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Start edit session
edit = arcpy.da.Editor(self.sde_path)
edit.startOperation()
# Your operations here
edit.stopOperation()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 18:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635654#M74521</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-07-23T18:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635659#M74522</link>
      <description>&lt;P&gt;A search cursor only accesses the data and does not apply any edits.&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;would be correct under the conditions of using either DeleteCursor or&amp;nbsp;UpdateCursor. If you are looking to get all unique values first and then delete any that are duplicates, then you would need to set your script to look like the following.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Feature = 'filepath of table or featurelass'
Searching = arcpy.da.SearchCursor( Feature, ['CommonIdField'] )
Updating = arcpy.da.UpdateCursor( Feature, ['CommonIdField'] )
Deleting = arcpy.da.DeleteCursor( Feature, ['CommonIdField'] )

# List comprehension of valid ids
ValidIDs = [ row[0] for row in Searching ]

# Delete rows based on matching ids in the list above
edit = arcpy.da.Editor(os.path.dirname(Feature ))
with edit as e:
	with Deleting as cursor:
		for row in cursor:
			r = row[0]
			if ValidIDs.count(r) &amp;gt;=2: 
				cursor.deleteRow(row)
				ValidIDs.remove(r)&lt;/LI-CODE&gt;&lt;P&gt;This should at least help guide you in the right direction.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp; or&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp;please correct me if the above script is incorrect. I have used this structure in previous scripts but it has been almost a year since I last used python.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 20:16:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635659#M74522</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-07-23T20:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635715#M74523</link>
      <description>&lt;P&gt;I think I've gotten off track here. My goal of searching for duplicates comes&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the stale data problem is solved. Sorry if I am misunderstanding.&lt;/P&gt;&lt;P&gt;Lets say I want to get all the data in table for easiness sake.&lt;/P&gt;&lt;P&gt;This returns data but it should not, since the table is empty, or shows as empty. I need it to return &lt;EM&gt;no&lt;/EM&gt; data when there is no data.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(full_table_path, field_names) as cursor:
                for row in cursor:
                         print(row)&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;I am not making any edits at this time, except in the UI - deleting the data in the table by clicking the delete button (then saving). Then running this query.&lt;/DIV&gt;&lt;DIV&gt;The screen shots show what happens. Sorry if I'm not getting your meaning. Thanks for the responses.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Jul 2025 20:23:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635715#M74523</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-07-23T20:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635735#M74524</link>
      <description>&lt;P&gt;Yes. If you have editor tracking on or any modifiable date field then all you need to search for are the dates that are closely associated with whatever timeframe you specify. Python is incredibly flexible in terms of dates. Like I also said earlier, within the cursor you can add a SQL query expression to quickly filter records. For example,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Define the feature class or table
feature_class = "path_to_your_feature_class"

# Define the SQL query (e.g., select features where 'Population' &amp;gt; 1000)
sql_query = "Population &amp;gt; 1000"

# Use a SearchCursor to iterate through the filtered records
with arcpy.da.SearchCursor(feature_class, ["Name", "Population"], sql_query) as cursor:
    for row in cursor:
        print(f"Name: {row[0]}, Population: {row[1]}")&lt;/LI-CODE&gt;&lt;P&gt;This code was autogenerated by Microsoft's CoPilot but it should give some ideas. The SQL query can filter for only records that meet that criteria.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 20:55:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635735#M74524</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-07-23T20:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635757#M74525</link>
      <description>&lt;P&gt;I don't see the connection between the responses and my original question, but thanks for responses nonetheless. Note: I did change the post title to better reflect the problem, i.e. it is&amp;nbsp;&lt;EM&gt;not&amp;nbsp;&lt;/EM&gt; a cursor problem.&lt;/P&gt;&lt;P&gt;So this solves my problem:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Delete the table data in Pro UI.&lt;/LI&gt;&lt;LI&gt;Under the Table tab &amp;gt; Manage Edits &amp;gt; Save&lt;/LI&gt;&lt;LI&gt;Run a search of all rows&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;No data is returned&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Just saving with the regular save icon in the corner, or with ctrl-s, did not suffice. Why is there a second save action? No idea, but this is what is required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 21:32:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635757#M74525</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-07-23T21:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635821#M74526</link>
      <description>&lt;P&gt;You have the general idea correct, but you are still assigning reference to the cursors in the initialization that persist until the death of the scope.&lt;/P&gt;&lt;P&gt;Not a major issue for small functions, but since most people (incorrectly I believe) write their primary scripts in the global scope, those references will live until the interpreter dies (ArcPro closes)&lt;/P&gt;&lt;P&gt;The only way to "pre-initialize" a cursor is to store the arguments as a tuple and destructure them when you create the cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cursor_args = ('featureclass', ['fields', ...], *args)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;values = [id for id, in SearchCursor(*cursor_args)]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the formatting, I'm on a phone right now and don't have access to a computer lol&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 04:55:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635821#M74526</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-24T04:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635822#M74527</link>
      <description>&lt;P&gt;There are 2 "things" in ArcPro. The Database and the project. Both of them are independent, but reliant on each other. By default, Ctrl+s in pro saves the aprx/project state (layers, selection, symbology, etc). You need to hit the "Save Edits" button under the edit tab to commit the staged changes to the database.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This makes sense when you think about how many different data sources you can have in a project. Saving a project is saving your active view of that data, but the data itself could be literally anything that supports SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 05:00:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635822#M74527</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-24T05:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635928#M74528</link>
      <description>&lt;P&gt;After I figured out the saving problem in the UI, and I moved to actually checking for duplicates&amp;nbsp;&lt;EM&gt;while&amp;nbsp;&lt;/EM&gt;actively inserting, this was the way to do it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 14:06:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1635928#M74528</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-07-24T14:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636356#M74540</link>
      <description>&lt;P&gt;I find cursors to be very confounding although I read they can be very powerful. Here's a use case. We have data we pull from a 3rd party app, do GIS magic, and put it back up into our geodatabase daily. We do this for both code violations and mapping certificates of occupancy for a local municipality.&amp;nbsp; Currently the workflow using a python script is:&amp;nbsp; pull data from a 3rd party app, do GIS magic, delete all (rows) of data in geodatabase (this can be over 20K records at a time)&amp;nbsp; and then append the new data, even though we KNOW some of that data hasn't changed. It would be great (and more efficient and better coding) to use an update cursor to update the values that have changed and then an insert cursor for those items that are new.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 14:01:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636356#M74540</guid>
      <dc:creator>ShariF</dc:creator>
      <dc:date>2025-07-25T14:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Database is stale after deleted table data using Pro UI and fetching using SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636399#M74544</link>
      <description>&lt;P&gt;Just out of curiosity, is your project setup to automatically allow edits to happen when the project is opened up and feature or table attributes can be updated? This could be causing your issue if the data source is something other than a feature class or table in either an sde or gdb.&lt;/P&gt;&lt;P&gt;The other thing you mentioned is that you are working with a file table. If you could please explain that further then it might be easier for anyone or any of us to help you with your given situation?&lt;/P&gt;&lt;P&gt;It sounds like your file table might be either an excel spreadsheet or some other table. If that is the case have you tried importing the table and see if the results are the same. You can use python to read other tables like excel but trying to run any edits on those tables or pull information from them could result in less than desirable behaviors. I have run into similar situations using external tables and usually importing them and then running python code on that table usually fixes the issue.&lt;/P&gt;&lt;P&gt;It is often best to run python as a standalone script using the modules that are designed to read those file types instead of bringing them into pro.&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp;may be able to affirm this or have a different take than mine.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 14:48:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636399#M74544</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-07-25T14:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636480#M74546</link>
      <description>&lt;P&gt;Here's a pretty lightweight implementation of a TableUpdater class that you could use. It leverages the 'EDITED@' token to compare update timestamps and then applies updates to existing rows with an update cursor and inserts rows that don't map to the target.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from datetime import datetime

from arcpy import (
    Exists, 
    Describe,
    Geometry,
)

from typing import (
    Generator,
    Any,
)

from arcpy.da import (
    Editor,
    SearchCursor,
    UpdateCursor,
    InsertCursor,
)

import arcpy.typing.describe as typedesc

from dataclasses import dataclass

@dataclass
class Changes:
    updates: list[int]
    inserts: list[int]
    deletes: list[int]
           
class TableUpdater: 
    
    Row = tuple[int, Geometry, datetime] # Type first 3 values of Row records
     
    def __init__(self, source_table: str, target_table: str) -&amp;gt; None:
        if not Exists(source_table) and Exists(target_table):
            raise ValueError('Invalid table paths!')
        
        self.target_table = target_table
        self.target_desc: typedesc.FeatureClass = Describe(target_table)
        
        self.source_table = source_table
        self.source_desc: typedesc.FeatureClass = Describe(source_table)
        
        # Do some filering to make sure we can use OID@ and SHAPE@ for the table cursors
        # By default a cursor will return SHAPE@XY
        self.source_shape_field = self.source_desc.shapeFieldName
        self.source_oid_field = self.source_desc.OIDFieldName
        self.source_fields = [field.name for field in self.source_desc.fields]
        
        self.target_shape_field = self.target_desc.shapeFieldName
        self.target_oid_field = self.target_desc.OIDFieldName
        self.target_fields = [field.name for field in self.target_desc.fields]
        
        self.target_editor = Editor(self.target_desc.workspace.catalogPath)
                
        self.fields = ['OID@', 'SHAPE@', 'EDITED@'] + [
            field
            for field in 
            set(self.source_fields) | set(self.target_fields)
            if field not in [self.source_oid_field, self.target_oid_field, self.source_shape_field, self.target_shape_field]
        ]
        
        self._table_diff = None
        
    @property
    def source_state(self):
        return self._gather_rows(self.source_table)
    
    @property
    def target_state(self):
        return self._gather_rows(self.target_table)
    
    @property
    def table_diff(self):
        if not self._table_diff:
            self._table_diff = self._get_table_diff()
        return self._table_diff
    
    def _gather_rows(self, table: str) -&amp;gt; dict[int, str]:
        """Gather all rows and their last updated times
        
        Parameters:
            table (str): Path to the table that needs updating
            
        Returns:
            ( dict[int, str] ): Mapping of OID to updated_at string
        """
        return {oid: updated_at for oid, updated_at in SearchCursor(table, ['OID@', 'EDITED@'])}
    
    def _get_table_diff(self) -&amp;gt; Changes:
        """Filter out records from the new_table that are unchanged from the old_table
        
        Returns:
            a list of OIDs in the new_table that need to be 
        """
        old_rows = self.target_state
        new_rows = self.source_state
        return Changes(
            updates=list(oid for oid in new_rows if oid in old_rows and old_rows[oid] &amp;lt; new_rows[oid]), 
            inserts=list(new_rows.keys() - old_rows.keys()), 
            deletes=list(old_rows.keys() - new_rows.keys()),
        )
    
    # Change Detection methods
    def _inserts(self) -&amp;gt; list[tuple[Any, ...]] | None:
        inserts = self.table_diff.inserts
        if inserts:
            if len(inserts) == 1:
                where_clause = f"{self.source_oid_field} = {inserts[0]}"
            else:    
                where_clause = f"{self.source_oid_field} IN ({','.join(map(str, inserts))})"
                
            return [row for row in SearchCursor(self.source_table, self.fields, where_clause=where_clause)]
    
    def _updates(self) -&amp;gt; dict[int, tuple[Any, ...]] | None:
        updates = self.table_diff.updates
        if updates:
            if len(updates) == 1:
                where_clause=f"{self.source_oid_field} = ({updates[0]})"
            else:
                where_clause=f"{self.source_oid_field} IN ({','.join(map(str, updates))})"
                
            return {
                row[0]: row
                for row in SearchCursor(self.source_table, self.fields, where_clause=where_clause)
            }
    
    def _deletes(self) -&amp;gt; list[int] | None:
        return self.table_diff.deletes or None
    
    def apply_changes(self) -&amp;gt; dict[str, list[int]]:
        """Applies all changed rows to target dataset
        
        Returns:
            ( dict[str, list[int]] ): A dictionary with 'updates' and 'insert' keys that have a list of oids updated or inserted
        """
        changes: dict[str, list[int]] = {
            'updates': [],
            'inserts': [],
            'deletes': [],
        }
        
        if ( updates := self._updates() ):
            if len(updates) == 1:
                oid = list(updates.keys())[0]
                where_clause = f"{self.target_oid_field} = {oid}"
            else:
                where_clause = f"{self.target_oid_field} IN ({','.join(map(str, updates.keys()))})"
            with self.target_editor, UpdateCursor(self.target_table, self.fields, where_clause=where_clause) as cur:
                changes['updates'] = [cur.updateRow(updates[oid]) or int(oid) for oid, *_ in cur]
        
        if ( inserts := self._inserts() ):
            with self.target_editor, InsertCursor(self.target_table, self.fields) as cur:
                changes['inserts'] = [cur.insertRow(row) for row in inserts]
        
        if ( deletes := self._deletes() ):
            if len(deletes) == 1:
                oid = deletes[0]
                where_clause = f"{self.target_oid_field} = {oid}"
            else:
                where_clause = f"{self.target_oid_field} IN ({','.join(map(str, deletes))})"
            with self.target_editor, UpdateCursor(self.target_table, self.fields, where_clause=where_clause) as cur:
                changes['deletes'] = [cur.deleteRow() or oid for oid, *_ in cur]
        
        return changes
    
def main():
    from pprint import pprint
    source = r'source_table'
    target = r'target_table'
    
    table_updater = TableUpdater(source, target)
    changes = table_updater.apply_changes()
    print(f"Updated {len(changes['updates'])} rows")
    print(f"Inserted {len(changes['inserts'])} rows")
    print(f"Deleted {len(changes['deletes'])} rows")
    pprint(changes)
    
if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use that as a rough base for what you're describing. I tried to use some advanced techniques in there so you can see the creative ways to use a cursor.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 17:05:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636480#M74546</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-25T17:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SearchCursor accurately</title>
      <link>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636487#M74547</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt;wow. Thank you. That looks daunting but I'll see if I can figure it out. I hope to see your blog about cursors.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 16:51:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/database-is-stale-after-deleted-table-data-using/m-p/1636487#M74547</guid>
      <dc:creator>ShariF</dc:creator>
      <dc:date>2025-07-25T16:51:04Z</dc:date>
    </item>
  </channel>
</rss>

