Skip to content

Commit c7157ef

Browse files
committed
add comments to clarify reasoning around email asserts
1 parent 17fe480 commit c7157ef

File tree

1 file changed

+13
-3
lines changed
  • src/sentry/api/serializers/models/organization_member

1 file changed

+13
-3
lines changed

src/sentry/api/serializers/models/organization_member/base.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,23 @@ def serialize(
100100
) -> OrganizationMemberResponse:
101101
serialized_user = attrs["user"]
102102
if obj.user_id:
103-
# Only use the user's primary email from the serialized user data
103+
# if the OrganizationMember has a user_id, the user has an account
104+
# `email` on the OrganizationMember will be null, so we need to pull
105+
# the email address from the user's actual account
104106
email = serialized_user["email"] if serialized_user else obj.email
105107
else:
106-
# For invited members, use the invitation email
108+
# when there is no user_id, the OrganizationMember is an invited user
109+
# and the email field on OrganizationMember will be populated, so we
110+
# will use it directly
107111
email = obj.email
108112

109-
# helping mypy - we know email will never be None based on the model
113+
# helping mypy - the email will always be populated at this point
114+
# in the case that it is a user that has an account, we pull the email
115+
# address above from the serialized_user. The email field on OrganizationMember
116+
# is null in the case, so it is necessary.
117+
#
118+
# invited users do not yet have a full account and the email field
119+
# on OrganizationMember will be populated in such cases
110120
assert email is not None
111121

112122
inviter_name = None

0 commit comments

Comments
 (0)