I am working with ArcMap 10.2. In the following code, I have a function, build_dictionary, that builds a dictionary that will be used to populate a field within another layer. With the second function, update_points, I am trying to use an UpdateCursor to iterate through each feature and if that feautre's OBJECTID is a key within the dictionary, populate a field called "RoutingStreetExtKey" with that key's value.

I have verified that the build_dictionary function works properly with an "AddMessage" (and therefore omitted the code). I return the dictionary in order to use it with the next function.

The problem occurs with the update_points function. As the script runs, I can see it iterate through the point layer, however it only updates the last feature. All other features have nothing written to the "RoutingStreetExtKey" field except the very last point feature. The last feauture is populated with the correct value.

I am concerned that I may not be passing the dictionary correctly from build_dictionary to update_points. Furthermore, is there something else I need to add to the body of UpdateCursor to ensure all features are being updated?

import arcpy
point_layer = arcpy.GetParameterAsText(0)
street_layer = arcpy.GetParameterAsText(1)

def build_dictionary():
    return ext_key_dict

def update_points(passed_dict):
    with arcpy.da.UpdateCursor(point_layer, ["OBJECTID", "RoutingStreetExtKey"]) as cursor_update:
        for new_row in cursor_update:
            obj_id = new_row[0]
            if obj_id in passed_dict:
                new_row[1] = passed_dict[obj_id]
def main():


closed as off-topic by Vince, whyzar, mgri, nmtoken, neogeomat Sep 13 '17 at 13:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Vince, whyzar, mgri, nmtoken, neogeomat
If this question can be reworded to fit the rules in the help center, please edit the question.


If it's only running on the last row, it might have gotten selected somewhere else in the process, so it might be worth trying:

arcpy.SelectLayerByAttribute_management(point_layer, "CLEAR_SELECTION")

right before you set up the UpdateCursor.

  • I made this change, but it's still only updating the last feature – Steven C Sep 12 '17 at 16:15
  • Can you return some keys for known object ids in your AddMessage? – Marc Pfister Sep 12 '17 at 16:25
  • Also could the last row be selected? – Marc Pfister Sep 12 '17 at 16:29
  • Yes, I can return keys for known objects. I have verified that the last row is not selected. – Steven C Sep 12 '17 at 16:52
  • Type mismatch? Your keys are strings but the OIDs are integers? I can't think of much else other than to throw in some print statements. – Marc Pfister Sep 12 '17 at 17:02

Your issue is in the below line I believe

if obj_id in passed_dict[obj_id]:

You're checking if the value obj_id is in the returned value of your dictionary for obj_id. If you want to see if the key obj_id is in the dictionary you need to use the following line:

if obj_id in passed_dict:
  • I've made this change, but it is still only updating the last feature – Steven C Sep 12 '17 at 16:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.