Arcpy error: updating attribute values in relationship class table

Discussion created by ericwerfel on Jun 21, 2018

I'm attempting to update the attribute values in a relationship class table using python. basically, i'm looking to update two count fields to see how many times each primary key occurs in the table, and then set a 'matchType', ie is it '1 to 1', '1 to many', etc...  here is my code: 

import arcpy

arcpy.env.workspace = 'C:\Users\Werfel\Desktop\Philly PIN\matches.gdb'

dor = {}
pwd = {}

with arcpy.da.SearchCursor('dor_pwd',['DOR_OBJECTID','PARCELID']) as cursor:
    for row in cursor:
        if row[0] not in dor.keys():
            dor[row[0]] = 1
            dor[row[0]] += 1
        if row[1] not in pwd.keys():
            pwd[row[1]] = 1
            pwd[row[1]] += 1

#edit = arcpy.da.Editor(arcpy.env.workspace)
#edit.startEditing(False, False)
with arcpy.da.UpdateCursor('dor_pwd',['DOR_OBJECTID','PARCELID','dorCount','pwdCount','matchType']) as cursor:
    for row in cursor:
        row[2] = dor[row[0]]
        row[3] = pwd[row[1]]
        if dor[row[0]]==1 and pwd[row[1]]==1: row[4]='1-1'
        if dor[row[0]]==1 and pwd[row[1]]>1: row[4]='M-1'
        if dor[row[0]]>1 and pwd[row[1]]==1: row[4]='1-M'
        if dor[row[0]]>1 and pwd[row[1]]>1: row[4]='M-M'



it crashes on line 32, with the message:

RuntimeError: Cannot reset foreign key values for an existing relationship row

thing is, none of the rows i'm updating are foreign keys. row[0] and row[1] are, but i'm only reading them.  is it bc the UpdateCursor retrieves these fields? 


i can think of other ways to do this (summary table, for example), but this is by far the fastest that i came up with, and i would like to run this every time i create a relationship, of which there will be thousands


fyi, the commented lines are to indicate that i have i tried with and without an edit session


any ideas?? thanks in advance,