Skip to content

Commit 1467f60

Browse files
committed
SDK-868: Carry on parsing rest of attribute if error parsing value
1 parent 3224a4d commit 1467f60

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

yoti_python_sdk/profile.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ def __init__(self, profile_attributes):
2020
field.value,
2121
field.content_type
2222
)
23-
24-
anchors = Anchor().parse_anchors(field.anchors)
25-
26-
self.attributes[field.name] = Attribute(field.name, value, anchors)
27-
28-
if field.name == config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS:
29-
self.try_convert_structured_postal_address_to_dict(field, anchors)
30-
3123
except Exception as exc:
3224
error = 'Error parsing profile attribute: "{0}"'.format(field.name)
3325
logging.warning('error: {0}, exception: {1} - {2}'.format(error, type(exc).__name__, exc))
26+
value = None
27+
28+
anchors = Anchor().parse_anchors(field.anchors)
29+
30+
self.attributes[field.name] = Attribute(field.name, value, anchors)
31+
32+
if field.name == config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS:
33+
self.try_convert_structured_postal_address_to_dict(field, anchors)
3434

3535
self.ensure_postal_address()
3636

yoti_python_sdk/tests/test_profile.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ def test_try_parse_int_value(string, expected_int):
113113
assert int_attribute.value == expected_int
114114

115115

116+
def test_error_parsing_attribute_has_none_value():
117+
int_attribute_name = "int_attribute"
118+
119+
attribute_list = create_single_attribute_list(
120+
name=int_attribute_name,
121+
value=str.encode("invalid_int"),
122+
anchors=None,
123+
content_type=Protobuf.CT_INT)
124+
125+
profile = Profile(attribute_list)
126+
127+
retrieved_string_attribute = profile.get_attribute(int_attribute_name)
128+
assert retrieved_string_attribute.name == int_attribute_name
129+
assert retrieved_string_attribute.value is None
130+
131+
116132
def test_error_parsing_attribute_does_not_affect_other_attribute():
117133
string_attribute_name = "string_attribute"
118134
int_attribute_name = "int_attribute"
@@ -134,14 +150,12 @@ def test_error_parsing_attribute_does_not_affect_other_attribute():
134150

135151
profile = Profile(attribute_list)
136152

137-
assert len(profile.attributes) == 1
153+
assert len(profile.attributes) == 2
138154

139155
retrieved_string_attribute = profile.get_attribute(string_attribute_name)
140156
assert retrieved_string_attribute.name == string_attribute_name
141157
assert retrieved_string_attribute.value == string_value
142158

143-
assert profile.get_attribute(int_attribute_name) is None
144-
145159

146160
def test_try_parse_structured_postal_address_uk():
147161
structured_postal_address = {ADDRESS_FORMAT_KEY: ADDRESS_FORMAT_VALUE,

0 commit comments

Comments
 (0)