Skip to content

Commit c658b52

Browse files
author
Carolyn Ranti
committed
Fix updating user if attribute value is an empty list
1 parent 1ea8a92 commit c658b52

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

djangosaml2/backends.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -230,27 +230,23 @@ def update_user(self, user, attributes, attribute_mapping,
230230
user_modified = False
231231
profile_modified = False
232232
for saml_attr, django_attrs in attribute_mapping.items():
233-
try:
234-
for attr in django_attrs:
235-
if hasattr(user, attr):
236-
user_attr = getattr(user, attr)
237-
if callable(user_attr):
238-
modified = user_attr(
239-
attributes[saml_attr])
240-
else:
241-
modified = self._set_attribute(
242-
user, attr, attributes[saml_attr][0])
243-
244-
user_modified = user_modified or modified
245-
246-
elif profile is not None and hasattr(profile, attr):
247-
modified = self._set_attribute(
248-
profile, attr, attributes[saml_attr][0])
249-
profile_modified = profile_modified or modified
250-
251-
except KeyError:
252-
# the saml attribute is missing
253-
pass
233+
attr_value_list = attributes.get(saml_attr)
234+
if not attr_value_list:
235+
continue
236+
237+
for attr in django_attrs:
238+
if hasattr(user, attr):
239+
user_attr = getattr(user, attr)
240+
if callable(user_attr):
241+
modified = user_attr(attr_value_list)
242+
else:
243+
modified = self._set_attribute(user, attr, attr_value_list[0])
244+
245+
user_modified = user_modified or modified
246+
247+
elif profile is not None and hasattr(profile, attr):
248+
modified = self._set_attribute(profile, attr, attr_value_list[0])
249+
profile_modified = profile_modified or modified
254250

255251
logger.debug('Sending the pre_save signal')
256252
signal_modified = any(

0 commit comments

Comments
 (0)