@dsblank Hi Doug,
There appears to be a subtle difference in the way a true gramps object and a DataDict representation work.
Background: this is in the context of updating a custom event role type (e.g. “Father”) to a built-in event role type (e.g. 11 - Father)
First the code using a Person object
person = self.get_person_from_handle("10244800c8436c7c90191cadb6db")
print(f"person.event_ref_list[0].role: {person.event_ref_list[0].role.get_object_state()}")
event_role = person.event_ref_list[0].get_role()
print(f"event_role: '{event_role.get_object_state()}'")
event_role.set(event_role.string)
print(f"event_role: '{event_role.get_object_state()}'")
print(f"person.event_ref_list[0].role.get_object_state(): '{person.event_ref_list[0].role.get_object_state()}'")
Essential: get a person by handle, get the event role of the first event ref, set the event role based on the current string and in the very last line, observe that the data in the person has in fact updated. Exactly as expected. Here’s the full output
person.event_ref_list[0].role: {'_class': 'EventRoleType', 'value': 0, 'string': 'Father'}
event_role: '{'_class': 'EventRoleType', 'value': 0, 'string': 'Father'}'
event_role: '{'_class': 'EventRoleType', 'value': 11, 'string': ''}'
person.event_ref_list[0].role.get_object_state(): '{'_class': 'EventRoleType', 'value': 11, 'string': ''}'
The role type changes from 'EventRoleType', 'value': 0, 'string': 'Father' to 'EventRoleType', 'value': 11, 'string': ''
Now the same code using DataDict. The only change is the first line
person = self.get_raw_person_data("10244800c8436c7c90191cadb6db")
print(f"person.event_ref_list[0].role: {person.event_ref_list[0].role.get_object_state()}")
event_role = person.event_ref_list[0].get_role()
print(f"event_role: '{event_role.get_object_state()}'")
event_role.set(event_role.string)
print(f"event_role: '{event_role.get_object_state()}'")
print(f"person.event_ref_list[0].role.get_object_state(): '{person.event_ref_list[0].role.get_object_state()}'")
And the output
person.event_ref_list[0].role: {'_class': 'EventRoleType', 'value': 0, 'string': 'Father'}
event_role: '{'_class': 'EventRoleType', 'value': 0, 'string': 'Father'}'
event_role: '{'_class': 'EventRoleType', 'value': 11, 'string': ''}'
person.event_ref_list[0].role.get_object_state(): '{'_class': 'EventRoleType', 'value': 0, 'string': 'Father'}'
In the final line, the role has not updated 'EventRoleType', 'value': 0, 'string': 'Father'
event_role has updated correctly.
It appears event_role is a value copy of the data when a DataDict is used, but a reference when the true object is used.
What have I overlooked?
Steve