0
0
mirror of https://github.com/gramps-project/gramps synced 2025-10-05 23:52:46 +02:00

Fix accessing an attribute in a DataDict

Previously, person_data.handle (where person_data is a DataDict) would
return the attribute from the "_object" if it existed. This is fine for
any non-data values (like strings). But for other items (like a Name),
it would return the Object (Name) rather than a DataDict of the Name.
This might be not noticed if you continued to access attr, but
Object["other_attr"] would crash.

Now, it properly returns a DataDict for all attributes, except those
that only exist on the object (such as methods).
This commit is contained in:
Doug Blank
2025-02-03 21:17:15 -05:00
committed by Nick Hall
parent 1dae935bea
commit 6272808b5f
3 changed files with 6 additions and 5 deletions

View File

@@ -106,7 +106,7 @@ class HasNameOf(Rule):
return False
if self.list[8] and not self.match_substring(8, surn.connector):
return False
if int(surn.origintype) == NameOriginType.PATRONYMIC:
if int(surn.origintype.value) == NameOriginType.PATRONYMIC:
if self.list[9] and not self.match_substring(9, surn.surname):
return False
return True

View File

@@ -109,7 +109,7 @@ class HasSoundexName(Rule):
"""
if soundex(str(surname.get_surname())) == self.soundex:
return True
if int(surname.origintype) == NameOriginType.PATRONYMIC:
if int(surname.origintype.value) == NameOriginType.PATRONYMIC:
if soundex(str(surname.surname)) == self.soundex:
return True
return False

View File

@@ -72,9 +72,7 @@ class DataDict(dict):
"this method cannot be used to access hidden attributes"
)
if "_object" in self:
return getattr(self["_object"], key)
elif key in self:
if key in self:
value = self[key]
if isinstance(value, dict):
return DataDict(value)
@@ -83,7 +81,10 @@ class DataDict(dict):
else:
return value
else:
# Some method or attribute not available
# otherwise. Cache it:
self["_object"] = data_to_object(self)
# And return the attr from the object:
return getattr(self["_object"], key)