mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-08-19 13:43:40 +00:00
Fix #295
KeyError could be raised when omparing versions with different fields
This commit is contained in:
parent
448463258e
commit
92bc326073
1 changed files with 34 additions and 11 deletions
|
@ -373,15 +373,26 @@ class HistoryEvent:
|
||||||
edits = []
|
edits = []
|
||||||
|
|
||||||
for field in self.edited_fields:
|
for field in self.edited_fields:
|
||||||
|
old_value = None
|
||||||
|
new_value = None
|
||||||
if field in hide:
|
if field in hide:
|
||||||
# Don't show sensitive information
|
# Don't show sensitive information, so leave values at None
|
||||||
edits.append((field, None, None))
|
pass
|
||||||
else:
|
else:
|
||||||
edits.append((
|
# Take into account keys that may exist in only one dict
|
||||||
field,
|
if field in self.previous_version.field_dict:
|
||||||
self._repr(field, self.previous_version.field_dict[field]),
|
old_value = self._repr(
|
||||||
self._repr(field, self.version.field_dict[field])
|
field,
|
||||||
))
|
self.previous_version.field_dict[field]
|
||||||
|
)
|
||||||
|
|
||||||
|
if field in self.version.field_dict:
|
||||||
|
new_value = self._repr(
|
||||||
|
field,
|
||||||
|
self.version.field_dict[field]
|
||||||
|
)
|
||||||
|
|
||||||
|
edits.append((field, old_value, new_value))
|
||||||
|
|
||||||
return edits
|
return edits
|
||||||
|
|
||||||
|
@ -438,9 +449,15 @@ class History:
|
||||||
v2.
|
v2.
|
||||||
"""
|
"""
|
||||||
fields = []
|
fields = []
|
||||||
|
v1_keys = set([k for k in v1.field_dict.keys() if k not in ignoring])
|
||||||
|
v2_keys = set([k for k in v2.field_dict.keys() if k not in ignoring])
|
||||||
|
|
||||||
for key in v1.field_dict.keys():
|
common_keys = v1_keys.intersection(v2_keys)
|
||||||
if key not in ignoring and v1.field_dict[key] != v2.field_dict[key]:
|
fields += list(v2_keys - v1_keys)
|
||||||
|
fields += list(v1_keys - v2_keys)
|
||||||
|
|
||||||
|
for key in common_keys:
|
||||||
|
if v1.field_dict[key] != v2.field_dict[key]:
|
||||||
fields.append(key)
|
fields.append(key)
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
@ -541,9 +558,15 @@ class VersionAction(HistoryEvent):
|
||||||
v2.
|
v2.
|
||||||
"""
|
"""
|
||||||
fields = []
|
fields = []
|
||||||
|
v1_keys = set([k for k in v1.field_dict.keys() if k not in ignoring])
|
||||||
|
v2_keys = set([k for k in v2.field_dict.keys() if k not in ignoring])
|
||||||
|
|
||||||
for key in v1.field_dict.keys():
|
common_keys = v1_keys.intersection(v2_keys)
|
||||||
if key not in ignoring and v1.field_dict[key] != v2.field_dict[key]:
|
fields += list(v2_keys - v1_keys)
|
||||||
|
fields += list(v1_keys - v2_keys)
|
||||||
|
|
||||||
|
for key in common_keys:
|
||||||
|
if v1.field_dict[key] != v2.field_dict[key]:
|
||||||
fields.append(key)
|
fields.append(key)
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
Loading…
Reference in a new issue