Select to view content in your preferred language

Arcpy.da.insertcursor, Update, Delete and the Related Table Indexing of a Geometric Network

1219
2
02-08-2019 12:07 PM
KendraHopper2
Emerging Contributor

Could it be possible that the attached python script is breaking the link between parent-child related records? Is it possible that the arcpy.da.insertcursor does not play well with related tables in a geometric network? It would be a great help if you had the time to peer-review the code in the attached arcpy_Update.txt. 

The GIS tables are related to each other via Relationship Classes within a Geometric Network. It was noticed that the number of related records returned using the "Related Tables" selection tools is different than if a "Select By Attributes" query was used. This is an open ticket with esri, however, the thought is that it is the script that is causing the issue, and scripting is out of support scope. 

Should a "Reconcile/Compres/Rebuild Indexes/Analyze" be included after the arcpy.da.insertcursor before the Update and Delete records?

As with any code, this has been pieced together from many different, and valuable sources with a special thank you to Richard Fairhurst‌'s blog post "Turbo Charging Data Manipulation with Python Cursors and Dictionaries": this script could not exist without the contents, comments and leads from that post.

My thanks in advance!

0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor

Having a SearchCursor and an InsertCursor or DeleteCursor operating simultaneously is a the most suspect part of your code that could lead to corrupt data.  Whenever I deal with InsertCursor and DeleteCursor operations, I do all SearchCursor operations first to build an insert dictionary containing lists of field values of the data to be inserted that are designed to be compatible with requirements of the InsertCursor and a delete dictionary of all ObjectIDs to be deleted.  Then I run a separate loop where only the InsertCursor is open and insert all of the new records from the items in the insert dictionary.  Then I run a separate loop where only the DeleteCursor is open and delete the objectIDs that match the ObjectID keys of the delete dictionary.

0 Kudos
AustinBodin1
New Contributor

Were you ever able to come up with a resolution to this issue? 

I'm experiencing a similar issue with a Python script inserting records into a related table. When inverting a selection of all records from the source->destination, the expected result would be only values which are Null or have a non-existent key, but I'm getting results that do exist in the parent feature class. 

With respect to Richard's reply, I do build a dictionary with the SearchCursors and then insert from the dictionary, so that is not the issue in my case, or yours, I suspect. 

0 Kudos