Skip to content

Commit 9b2b085

Browse files
committed
Don't crash if group has no creator
Fixes hypothesis#8734
1 parent f1669fd commit 9b2b085

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

h/jinja_extensions/navbar_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def navbar_data(request):
4141
"name": group.name,
4242
"pubid": group.pubid,
4343
"relationship": (
44-
"Creator" if group.creator.username == username else None
44+
"Creator"
45+
if group.creator and group.creator.username == username
46+
else None
4547
),
4648
}
4749
for group in groups

tests/unit/h/jinja2_extensions/navbar_data_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ def test_it(self, pyramid_request, user):
5050
"username_url": f"http://example.com/users/{user.username}",
5151
}
5252

53+
def test_it_with_a_group_with_no_creator(
54+
self, pyramid_request, user, factories, group_list_service
55+
):
56+
user.groups = group_list_service.associated_groups.return_value = [
57+
factories.Group(creator=None)
58+
]
59+
pyramid_request.user = user
60+
61+
result = navbar_data(pyramid_request)
62+
63+
assert result["groups_suggestions"] == [
64+
{
65+
"name": group.name,
66+
"pubid": group.pubid,
67+
"relationship": None,
68+
}
69+
for group in user.groups
70+
]
71+
5372
def test_it_with_no_user(self, pyramid_request, group_list_service):
5473
pyramid_request.user = None
5574
group_list_service.associated_groups.return_value = []

0 commit comments

Comments
 (0)